Includes both the servo and Dc motor. Needs more comments on the servo side.
Dependencies: Motor Servo mbed
Fork of lab3integrated by
lab3integrated.cpp
- Committer:
- tmaly45
- Date:
- 2018-10-03
- Revision:
- 1:efdd0b0bbdbc
- Parent:
- 0:f5f82650e679
- Child:
- 2:df17a1850217
File content as of revision 1:efdd0b0bbdbc:
//Integrated Servo and Motor // MIDN 3/C Stites and Maly // Modified 10/2/18 #include "mbed.h" #include "Servo.h" #include "Motor.h" //preprocessors to include Servo and Motor Servo kenny(p21); Servo barb(p22); Motor m(p26, p29, p30); // Assigns the PwmOut (pwm) pin, DigitalOut (fwd) pin, and Digital Out (rev) pin int main() { barb.calibrate(0.0009,90); kenny.calibrate(0.0009,90); kenny = 0; barb = 1; float k = 0.2; // value of initial speed & variable to define speed float i, j; // used in 'for' loops while(1) { for(k=0.2; k<1.0; k += 0.1) //Increases the value of k from 0.2 to 0.99. k is the speed of DC Motor { m.speed(k); // Sets the speed of the DC Motor to whatever value k is as it increases for (i=0; i<90; i++) // This 'for' loop turns the two Servos in opposite directions. { // It is set after the speed of the Motor is set so they move along with the DC Motor barb = 1 - i*0.0111; kenny = i*0.0111; wait(.0555); } m.speed(-k); //Sets the speed of the DC motor in the opposite direction at k speed. for (j=0; j<90; j++)// This 'for' loop turns the two Servos in opposite directions from each other and from the step before. {// It is set after the speed/direction change of the DC Motor so the Servos change direction the same time the DC motors do. kenny = 1 - j*0.0111; barb = j*0.0111; wait(.0555); } } m.speed(1); // This is for when the DC motor reaches full speed, which is 1. This will start at the end of the 'for' loop of the DC motor speed (k). for (i=0; i<90; i++)// Again, a 'for' loop to turn the two Servo motors in opposite directions while the DC motor turns. { barb = 1 - i*0.0111; kenny = i*0.0111; wait(.0555); } m.speed(-1); // Turns the DC motor at full speed in the opposite direction. for (j=0; j<90; j++)// Again, a 'for' loop to turn the two Servo motors in opposite directions while the DC motor turns. { kenny = 1 - j*0.0111; barb = j*0.0111; wait(.0555); } } }