how to solve the following two programs?

timer Asked: Nov 7th, 2016

Question description

Part 1: Use the Servo class

Write an Arduino program called two_servos.ino that controls two Servo objects in different ways.

The first Servo object must sweep from 0 to 180 degrees in steps (or units) determined by keyboard input (via serial communication). The range of step sizes valid for this problem is 1 to 90. If any input other than the integers 1-90 is given, you should simply ignore it.

Until an input is given, assume a step size of 1. If and when subsequent inputs are given, the sweeping should adjust immediately to the new step size, without resetting to 0 degrees.

When the position of the servo reaches 180 degrees, it should reset to 0 degrees and continue sweeping.

NOTE: You need to delay a reasonable amount in your loop, so that the complete sweep from 0 to 180 can be seen (i.e., the position does not change too quickly to be observed). Delaying about 500 milliseconds works well.

Control of the second Servo object is your choice. That is, you may move the servo to various positions and place delays between movements. The values used to determine the positions and/or delays can be collected and/or computed in any way you choose. For example, consider collecting values from sensors and/or keyboard input. You can use these inputs as is, or involve these inputs in computations to produce the values used by your servo.

Note that the servo should animate in a way different, and more interesting, than the Lab 6 activity.

Also note that both Servo objects should be controllable at the same time in a single run of your Arduino program.

Most likely your Arduino kit contains only one micro or hobby servo. Partner with a classmate to share servos for completing this assignment. (Do not share servo code for this assignment.) If you are unable to coordinate with a classmate, see the course staff who has several servos that can be loaned out.

During the demos in lab, the course staff will have extra servos for you to use. You should prepare for the demo by wiring one of your servos completely and wiring the other servo partially so that you can simply attach it during the demo.

Zip the Arduino folder that contains your two_servos.ino program and submit the zip file. (The folder should not contain any other files.)

Part 2: Build a Motor class

Write a C++ class that models a toy motor in the following way:

  • Data — a pin used to connect to the motor
  • Actions:
    • creating the motor object, which takes a specific number for setting the pin
    • turning the motor on, which takes no input and gives no output
    • turning the motor off, which takes no input and gives no output
    • spinning the motor at a certain speed for a certain amount of time, which takes the speed and duration as input but gives no output

You are encouraged to add additional data and/or actions to your model of a toy motor. However, you must provide the behavior above as a minimum, and it must work correctly, before the course staff will consider additional behavior.

Put the declaration of your Motor class in a file called motor.h and the implementation of your Motor member functions in a file called motor.cpp.

Write an Arduino program called motor_demo.ino that creates one or more objects of your Motor class and uses the object(s) to demonstrate the full functionality of your class. To make the demo more fun and interesting, as well as making it easier for the course staff to observe the changing functionality, consider using the toy motor to move or spin a physical prop (such as a flag, pinwheel, toy wheel, fan blades).

NOTE: Do not include any libraries in any file of your project, other than “Arduino.h” and “motor.h”.

To facilitate demoing solutions to both parts of this assignment in the same session on Friday, November 11, make sure that you can wire your board with two servos and at least one toy motor.

Zip the Arduino folder that contains your motor_demo.ino, motor.h, motor.cpp files and submit the zip file. (The folder should not contain any other files.)

Studypool has helped 1,244,100 students
flag Report DMCA
Similar Questions
Hot Questions
Related Tags
Study Guides

Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors