Code from part C of the servo lab
Dependencies: Motor Servo mbed
Revision 0:9e14f994576d, committed 2015-02-27
- Comitter:
- probst
- Date:
- Fri Feb 27 04:21:15 2015 +0000
- Commit message:
- Part D servo lab;
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Motor.lib Fri Feb 27 04:21:15 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/balambur/code/Motor/#99e7708a5276
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Servo.lib Fri Feb 27 04:21:15 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/simon/code/Servo/#36b69a7ced07
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Feb 27 04:21:15 2015 +0000 @@ -0,0 +1,67 @@ +// define necessary includes +#include "mbed.h" +#include "Motor.h" +#include "Servo.h" +#define PULSE .0009 +#define MAX 90 + +//define the two servos +Servo servoOne(p21); +Servo servoTwo(p22); + +//define the motor +Motor m(p23,p24,p25); +Serial pc(USBTX, USBRX); + + +int main() +{ + //calibrate the two servos + servoOne.calibrate(PULSE,MAX); + servoTwo.calibrate(PULSE,MAX); + + //declare the initial motor speed + double motorSpeed = .1; + + //set the tow servoes to their initial positions + float position = 0; + float positionTwo = 1; + + while(1) + { + //declare the initial positions + servoOne = position; //0 + servoTwo = positionTwo; //1 + + //spin the servos in opposite directions forward + while(position < 1 && positionTwo > 0) + { + if(motorSpeed != 1){motorSpeed = motorSpeed + .1;}; + m.speed(motorSpeed); + position = position + .0001; + positionTwo = positionTwo - .0001; + servoOne = position; + servoTwo = positionTwo; + + + wait(.00025); + + } + + //spin the servos in opposite positions backwards + while(position > 0 && positionTwo < 1) + { + m.speed(-motorSpeed); + position = position - .0001; + positionTwo = positionTwo + .0001; + servoOne = position; + servoTwo = positionTwo; + wait(.00025); + + } + + + + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Feb 27 04:21:15 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/9ad691361fac \ No newline at end of file