Start of project 2
Dependencies: Motor Servo mbed mbed-rtos
main.cpp.orig@4:a3e95c9d56d5, 2018-10-10 (annotated)
- Committer:
- nhersom
- Date:
- Wed Oct 10 12:33:06 2018 +0000
- Revision:
- 4:a3e95c9d56d5
updated code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nhersom | 4:a3e95c9d56d5 | 1 | #include "mbed.h" |
nhersom | 4:a3e95c9d56d5 | 2 | #include "stdio.h" |
nhersom | 4:a3e95c9d56d5 | 3 | #include "Motor.h" |
nhersom | 4:a3e95c9d56d5 | 4 | #include "math.h" |
nhersom | 4:a3e95c9d56d5 | 5 | #include "Servo.h" |
nhersom | 4:a3e95c9d56d5 | 6 | |
nhersom | 4:a3e95c9d56d5 | 7 | int s1, s3, s4, i; |
nhersom | 4:a3e95c9d56d5 | 8 | float x; |
nhersom | 4:a3e95c9d56d5 | 9 | DigitalIn swtch1(p19); |
nhersom | 4:a3e95c9d56d5 | 10 | DigitalIn swtch3(p20); |
nhersom | 4:a3e95c9d56d5 | 11 | DigitalIn swtch4(p21); |
nhersom | 4:a3e95c9d56d5 | 12 | AnalogIn turn(p22); |
nhersom | 4:a3e95c9d56d5 | 13 | Motor m(p26, p30, p29); |
nhersom | 4:a3e95c9d56d5 | 14 | |
nhersom | 4:a3e95c9d56d5 | 15 | Servo back(p21); |
nhersom | 4:a3e95c9d56d5 | 16 | Servo angle(p22); |
nhersom | 4:a3e95c9d56d5 | 17 | |
nhersom | 4:a3e95c9d56d5 | 18 | int main() { |
nhersom | 4:a3e95c9d56d5 | 19 | s1 = swtch1.read(); //read state of switch 1 |
nhersom | 4:a3e95c9d56d5 | 20 | back.calibrate(0.0009, 90.0); //calculate's servos timing by setting pulse width and range |
nhersom | 4:a3e95c9d56d5 | 21 | |
nhersom | 4:a3e95c9d56d5 | 22 | while (s1 == 1) |
nhersom | 4:a3e95c9d56d5 | 23 | { |
nhersom | 4:a3e95c9d56d5 | 24 | for (i = 0; i < 18; i++) //moves monument forward |
nhersom | 4:a3e95c9d56d5 | 25 | { |
nhersom | 4:a3e95c9d56d5 | 26 | back = 0; |
nhersom | 4:a3e95c9d56d5 | 27 | back = (0.0 + (i/18.0)); |
nhersom | 4:a3e95c9d56d5 | 28 | s1 = swtch1.read(); //read state of switch 1 |
nhersom | 4:a3e95c9d56d5 | 29 | }//end of for loop |
nhersom | 4:a3e95c9d56d5 | 30 | |
nhersom | 4:a3e95c9d56d5 | 31 | for (i = 0; i < 35; i++) //moves monument backwards |
nhersom | 4:a3e95c9d56d5 | 32 | { |
nhersom | 4:a3e95c9d56d5 | 33 | back = 1; |
nhersom | 4:a3e95c9d56d5 | 34 | back = (1.0 - (i/18.0)); |
nhersom | 4:a3e95c9d56d5 | 35 | s1 = swtch1.read(); //read state of switch 1 |
nhersom | 4:a3e95c9d56d5 | 36 | }//end of for loop |
nhersom | 4:a3e95c9d56d5 | 37 | |
nhersom | 4:a3e95c9d56d5 | 38 | }//end of while loop |
nhersom | 4:a3e95c9d56d5 | 39 | |
nhersom | 4:a3e95c9d56d5 | 40 | |
nhersom | 4:a3e95c9d56d5 | 41 | while (1) |
nhersom | 4:a3e95c9d56d5 | 42 | { |
nhersom | 4:a3e95c9d56d5 | 43 | x = turn.read(); |
nhersom | 4:a3e95c9d56d5 | 44 | angle = x; |
nhersom | 4:a3e95c9d56d5 | 45 | wait (.05); |
nhersom | 4:a3e95c9d56d5 | 46 | |
nhersom | 4:a3e95c9d56d5 | 47 | } //end of while loop |
nhersom | 4:a3e95c9d56d5 | 48 | |
nhersom | 4:a3e95c9d56d5 | 49 | } //end of int main |