Start of project 2
Dependencies: Motor Servo mbed mbed-rtos
Diff: main.cpp
- Revision:
- 5:27689dbb0c6e
- Parent:
- 4:a3e95c9d56d5
- Child:
- 6:3dc339508843
--- a/main.cpp Wed Oct 10 12:33:06 2018 +0000 +++ b/main.cpp Tue Oct 16 13:16:20 2018 +0000 @@ -6,30 +6,32 @@ 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); -AnalogIn turn(p22); Motor m(p26, p30, p29); DigitalIn sw1 (p16) ; -Servo back(p21); -Servo angle(p22); +Servo back(p21); //servo to move monument on turn table +Servo angle(p22); //servo to adjust horizontal angle of arm int main() { s1 = swtch1.read(); //read state of switch 1 + 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) { - for (i = 0; i < 18; i++) //moves monument forward + for (i = 0; i < 18; i++) //moves monument 180 degrees one way { back = 0; back = (0.0 + (i/18.0)); s1 = swtch1.read(); //read state of switch 1 }//end of for loop - for (i = 0; i < 35; i++) //moves monument backwards + for (i = 0; i < 35; i++) //moves monument back and another 180 degress the opposite way { back = 1; back = (1.0 - (i/18.0)); @@ -39,29 +41,40 @@ }//end of while loop - while (1) - { - x = turn.read(); - angle = x; - wait (.05); - - } //end of while loop + +//Adjust horiztonal angle with switch 2/dial + while(1) { + y = turn.read(); //reads the state of the dial the user changes + printf("The dial is at %f\n", x); + angle.write(y); //makes the servo turn according to the dial + printf("The servo is at %f\n", x); + +} //end of while loop + + - sw1.read(); - if (sw1==1) { + sw3.read(); //read state of switch 3 (launch the cover) + if (sw3==1) { while(1) { m.speed(1); wait (.15); m.speed(0); wait (1); break; - } + } //end of while + } //end of if + + + + + sw4.read(); //read state of switch 4 (retract arm to try again) + if (s4 == 1){ while(1) { m.speed(-.25); wait(.6); m.speed(0); wait(1); break; - } - } + } //end of while + } //end of if } //end of int main