![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
It begins
Dependencies: SDFileSystem mbed-rtos mbed wave_player
Fork of BAT_senior_design by
main.cpp@1:4347df0fafb1, 2017-10-04 (annotated)
- Committer:
- nnguyen45
- Date:
- Wed Oct 04 14:57:25 2017 +0000
- Revision:
- 1:4347df0fafb1
- Parent:
- 0:9eda4611081a
- Child:
- 2:6836f515bb50
testnhi
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aismail1997 | 0:9eda4611081a | 1 | #include "mbed.h" |
aismail1997 | 0:9eda4611081a | 2 | #include "Servo.h" |
aismail1997 | 0:9eda4611081a | 3 | |
aismail1997 | 0:9eda4611081a | 4 | PwmOut myservo(p21); |
aismail1997 | 0:9eda4611081a | 5 | DigitalIn pb1 (p20); |
aismail1997 | 0:9eda4611081a | 6 | //AnalogIn linpot(p20); |
aismail1997 | 0:9eda4611081a | 7 | Serial pc(USBTX, USBRX); |
aismail1997 | 0:9eda4611081a | 8 | DigitalOut myled(LED1); |
aismail1997 | 0:9eda4611081a | 9 | |
aismail1997 | 0:9eda4611081a | 10 | int main() |
aismail1997 | 0:9eda4611081a | 11 | { |
aismail1997 | 0:9eda4611081a | 12 | // button up: state = 0, button halfway: state = 1; button down: state = 2 |
aismail1997 | 0:9eda4611081a | 13 | //int state = 0; |
nnguyen45 | 1:4347df0fafb1 | 14 | //Nhi |
aismail1997 | 0:9eda4611081a | 15 | pc.printf("begin\n"); |
aismail1997 | 0:9eda4611081a | 16 | int state = 2; |
aismail1997 | 0:9eda4611081a | 17 | pb1.mode(PullUp); |
aismail1997 | 0:9eda4611081a | 18 | wait(.001); |
aismail1997 | 0:9eda4611081a | 19 | for(int i=0; i<=3; i++) { |
aismail1997 | 0:9eda4611081a | 20 | myservo = i/100.0; |
aismail1997 | 0:9eda4611081a | 21 | wait(0.01); |
aismail1997 | 0:9eda4611081a | 22 | } |
aismail1997 | 0:9eda4611081a | 23 | while(1) { |
aismail1997 | 0:9eda4611081a | 24 | // Servo code |
aismail1997 | 0:9eda4611081a | 25 | if (pb1 == 1 && state == 2) { |
aismail1997 | 0:9eda4611081a | 26 | while(pb1 == 1) |
aismail1997 | 0:9eda4611081a | 27 | myled = 1; |
aismail1997 | 0:9eda4611081a | 28 | // rotate 90 degrees one way |
aismail1997 | 0:9eda4611081a | 29 | for(int i=3; i<=7; i++) { |
aismail1997 | 0:9eda4611081a | 30 | myservo = i/100.0; |
aismail1997 | 0:9eda4611081a | 31 | wait(0.01); |
aismail1997 | 0:9eda4611081a | 32 | } |
aismail1997 | 0:9eda4611081a | 33 | state = 1; |
aismail1997 | 0:9eda4611081a | 34 | } |
aismail1997 | 0:9eda4611081a | 35 | //wait(1.0); |
aismail1997 | 0:9eda4611081a | 36 | // rotate 90 degrees other way |
aismail1997 | 0:9eda4611081a | 37 | if (pb1 == 1 && state == 1) { |
aismail1997 | 0:9eda4611081a | 38 | while(pb1 == 1) |
aismail1997 | 0:9eda4611081a | 39 | myled = 0; |
aismail1997 | 0:9eda4611081a | 40 | for(int i=7; i>3; i--) { |
aismail1997 | 0:9eda4611081a | 41 | myservo = i/100.0; |
aismail1997 | 0:9eda4611081a | 42 | wait(0.01); |
aismail1997 | 0:9eda4611081a | 43 | } |
aismail1997 | 0:9eda4611081a | 44 | //wait(0.1); |
aismail1997 | 0:9eda4611081a | 45 | state = 2; |
aismail1997 | 0:9eda4611081a | 46 | } |
aismail1997 | 0:9eda4611081a | 47 | //wait(1.0); |
aismail1997 | 0:9eda4611081a | 48 | |
aismail1997 | 0:9eda4611081a | 49 | // read linear potentiometer |
aismail1997 | 0:9eda4611081a | 50 | //if (linpot < 0.5) { |
aismail1997 | 0:9eda4611081a | 51 | //float potval = linpot; |
aismail1997 | 0:9eda4611081a | 52 | //pc.printf("linear pot: %f\n", potval); |
aismail1997 | 0:9eda4611081a | 53 | } |
aismail1997 | 0:9eda4611081a | 54 | } |