DC motor and Servo
Dependencies: DC_Motor Servo mbed
Fork of Lab2_41 by
Diff: main.cpp
- Revision:
- 1:88e499bfdcc7
- Parent:
- 0:5ea7adc7e9cf
- Child:
- 2:ecf535666eb3
diff -r 5ea7adc7e9cf -r 88e499bfdcc7 main.cpp --- a/main.cpp Thu Sep 27 19:12:14 2018 +0000 +++ b/main.cpp Wed Oct 03 18:31:18 2018 +0000 @@ -1,24 +1,29 @@ + #include "mbed.h" #include "Servo.h" +#include "Motor.h" -Servo myservo1(p21); +Servo myservo(p21); Servo myservo2(p22); +Motor(PinName pwm, PinName fwd, PinName rev): -int main() + int i; + +int main() { -myservo1.calibrate(0.0009,90); -myservo2.calibrate(0.0009,90); - while(1) - { - myservo1=1; - myservo2=0; - wait(5); - myservo1=0; - myservo2=1; - wait(5); - - - } + myservo.calibrate(0.0009,90); + myservo2.calibrate(0.0009, 90); - + while(1) { + for( i=0; i<180; i++) { + myservo = i/180.0; + myservo2=(180.0-i)/180.0; + wait(0.025); + } + for( i=180; i>0; i--) { + myservo = i/180.0; + myservo2=(180.0-i)/180.0; + wait(0.025); } +} +}