![](/media/cache/group/220px-Herndon_Monument_Climb.jpg.50x50_q85.jpg)
Start of project 2
Dependencies: Motor Servo mbed mbed-rtos
main.cpp@1:7133819e4265, 2018-10-09 (annotated)
- Committer:
- m215676
- Date:
- Tue Oct 09 13:30:18 2018 +0000
- Revision:
- 1:7133819e4265
- Parent:
- 0:9347308e8e1a
- Child:
- 2:60a8105d0d20
Worked on switch 1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
m215676 | 0:9347308e8e1a | 1 | #include "mbed.h" |
m215676 | 0:9347308e8e1a | 2 | #include "stdio.h" |
m215676 | 0:9347308e8e1a | 3 | #include "Motor.h" |
m215676 | 0:9347308e8e1a | 4 | #include "math.h" |
m215676 | 0:9347308e8e1a | 5 | |
m215676 | 1:7133819e4265 | 6 | int s1, s3, s4, i; |
m215676 | 1:7133819e4265 | 7 | DigitalIn swtch1(p19); |
m215676 | 1:7133819e4265 | 8 | DigitalIn swtch3(p20); |
m215676 | 1:7133819e4265 | 9 | DigitalIn swtch4(p21); |
m215676 | 0:9347308e8e1a | 10 | |
m215676 | 0:9347308e8e1a | 11 | Motor m(p26, p30, p29); |
m215676 | 1:7133819e4265 | 12 | |
m215676 | 1:7133819e4265 | 13 | Servo back(p21); |
m215676 | 1:7133819e4265 | 14 | Servo angle(p22); |
m215676 | 0:9347308e8e1a | 15 | |
m215676 | 0:9347308e8e1a | 16 | int main() { |
m215676 | 1:7133819e4265 | 17 | s1 = swtch1.read(); //read state of switch 1 |
m215676 | 1:7133819e4265 | 18 | back.calibrate(0.0009, 90.0); //calculate's servos timing by setting pulse width and range |
m215676 | 0:9347308e8e1a | 19 | |
m215676 | 1:7133819e4265 | 20 | while (s1 == 1) |
m215676 | 1:7133819e4265 | 21 | { |
m215676 | 1:7133819e4265 | 22 | for (i = 0; i < 18; i++) //moves monument forward |
m215676 | 1:7133819e4265 | 23 | { |
m215676 | 1:7133819e4265 | 24 | back = 0; |
m215676 | 1:7133819e4265 | 25 | back = (0.0 + (i/18.0)); |
m215676 | 1:7133819e4265 | 26 | s1 = swtch1.read(); //read state of switch 1 |
m215676 | 1:7133819e4265 | 27 | }//end of for loop |
m215676 | 1:7133819e4265 | 28 | |
m215676 | 1:7133819e4265 | 29 | for (i = 0; i < 35; i++) //moves monument backwards |
m215676 | 1:7133819e4265 | 30 | { |
m215676 | 1:7133819e4265 | 31 | back = 1; |
m215676 | 1:7133819e4265 | 32 | back = (1.0 - (i/18.0)); |
m215676 | 1:7133819e4265 | 33 | s1 = swtch1.read(); //read state of switch 1 |
m215676 | 1:7133819e4265 | 34 | }//end of for loop |
m215676 | 1:7133819e4265 | 35 | |
m215676 | 1:7133819e4265 | 36 | }//end of while loop |
m215676 | 1:7133819e4265 | 37 | |
m215676 | 0:9347308e8e1a | 38 | } //end of int main |