Start of project 2
Dependencies: Motor Servo mbed mbed-rtos
Diff: main.cpp
- Revision:
- 6:3dc339508843
- Parent:
- 5:27689dbb0c6e
- Child:
- 7:adcdd7556997
diff -r 27689dbb0c6e -r 3dc339508843 main.cpp --- a/main.cpp Tue Oct 16 13:16:20 2018 +0000 +++ b/main.cpp Tue Oct 16 13:38:55 2018 +0000 @@ -3,16 +3,19 @@ #include "Motor.h" #include "math.h" #include "Servo.h" +#include "rtos.h" //need to add this library for multiple functions running at once + + int s1, s3, s4, i; float x; float y; -AnalogIn turn(p15); //turn dial to adjust servo for horizontal angle of arm -DigitalIn swtch1(p19); -DigitalIn swtch3(p20); -DigitalIn swtch4(p21); -Motor m(p26, p30, p29); -DigitalIn sw1 (p16) ; +AnalogIn turn(p15); //turn dial to adjust servo for horizontal angle of arm SWITCH 2 +DigitalIn swtch1(p19); //moves herndon monument on turn table continuously while switch is on +DigitalIn swtch3(p20); //releases the cover when switch 3 is turned on +DigitalIn swtch4(p21); //retracts arm back to starting position to try again +Motor m(p26, p30, p29); //launches the cover +//DigitalIn sw1 (p16) ; not sure why this is here - maybe broken pin Servo back(p21); //servo to move monument on turn table Servo angle(p22); //servo to adjust horizontal angle of arm @@ -22,7 +25,7 @@ angle.calibrate(0.0009, 90.0); back.calibrate(0.0009, 90.0); //calculate's servos timing by setting pulse width and range - while (s1 == 1) + while (s1 == 1) //moves herndon monument continuously on turn table { for (i = 0; i < 18; i++) //moves monument 180 degrees one way { @@ -31,13 +34,17 @@ s1 = swtch1.read(); //read state of switch 1 }//end of for loop - for (i = 0; i < 35; i++) //moves monument back and another 180 degress the opposite way + i=0; + + for (i = 0; i < 18; i++) //moves monument back and another 180 degress the opposite way { back = 1; back = (1.0 - (i/18.0)); s1 = swtch1.read(); //read state of switch 1 }//end of for loop + i = 0; + }//end of while loop @@ -56,9 +63,11 @@ sw3.read(); //read state of switch 3 (launch the cover) if (sw3==1) { while(1) { - m.speed(1); - wait (.15); - m.speed(0); + printf("motor on"); + m.speed(1.0); + wait (.4); + printf("motor off"); + m.speed(0.0); wait (1); break; } //end of while @@ -70,11 +79,13 @@ sw4.read(); //read state of switch 4 (retract arm to try again) if (s4 == 1){ while(1) { + printf("reversed"); m.speed(-.25); wait(.6); + printf("motor off"); m.speed(0); wait(1); break; } //end of while } //end of if - } //end of int main +