It begins
Dependencies: SDFileSystem mbed-rtos mbed wave_player
Fork of BAT_senior_design by
main.cpp@3:9ed43e974156, 2017-10-06 (annotated)
- Committer:
- aismail1997
- Date:
- Fri Oct 06 13:43:36 2017 +0000
- Revision:
- 3:9ed43e974156
- Parent:
- 2:6836f515bb50
- Child:
- 4:cc181f8f2bd1
test - azra
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 | 3:9ed43e974156 | 4 | // Azra |
aismail1997 | 3:9ed43e974156 | 5 | |
aismail1997 | 0:9eda4611081a | 6 | PwmOut myservo(p21); |
aismail1997 | 0:9eda4611081a | 7 | DigitalIn pb1 (p20); |
aismail1997 | 0:9eda4611081a | 8 | //AnalogIn linpot(p20); |
aismail1997 | 0:9eda4611081a | 9 | Serial pc(USBTX, USBRX); |
aismail1997 | 0:9eda4611081a | 10 | DigitalOut myled(LED1); |
aismail1997 | 0:9eda4611081a | 11 | |
aismail1997 | 0:9eda4611081a | 12 | int main() |
aismail1997 | 0:9eda4611081a | 13 | { |
aismail1997 | 0:9eda4611081a | 14 | // button up: state = 0, button halfway: state = 1; button down: state = 2 |
aismail1997 | 0:9eda4611081a | 15 | //int state = 0; |
aismail1997 | 0:9eda4611081a | 16 | pc.printf("begin\n"); |
aismail1997 | 0:9eda4611081a | 17 | int state = 2; |
aismail1997 | 0:9eda4611081a | 18 | pb1.mode(PullUp); |
aismail1997 | 0:9eda4611081a | 19 | wait(.001); |
aismail1997 | 0:9eda4611081a | 20 | for(int i=0; i<=3; i++) { |
aismail1997 | 0:9eda4611081a | 21 | myservo = i/100.0; |
aismail1997 | 0:9eda4611081a | 22 | wait(0.01); |
aismail1997 | 0:9eda4611081a | 23 | } |
aismail1997 | 0:9eda4611081a | 24 | while(1) { |
aismail1997 | 0:9eda4611081a | 25 | // Servo code |
aismail1997 | 0:9eda4611081a | 26 | if (pb1 == 1 && state == 2) { |
aismail1997 | 0:9eda4611081a | 27 | while(pb1 == 1) |
aismail1997 | 0:9eda4611081a | 28 | myled = 1; |
aismail1997 | 0:9eda4611081a | 29 | // rotate 90 degrees one way |
aismail1997 | 0:9eda4611081a | 30 | for(int i=3; i<=7; i++) { |
aismail1997 | 0:9eda4611081a | 31 | myservo = i/100.0; |
aismail1997 | 0:9eda4611081a | 32 | wait(0.01); |
aismail1997 | 0:9eda4611081a | 33 | } |
aismail1997 | 0:9eda4611081a | 34 | state = 1; |
aismail1997 | 0:9eda4611081a | 35 | } |
aismail1997 | 0:9eda4611081a | 36 | //wait(1.0); |
aismail1997 | 0:9eda4611081a | 37 | // rotate 90 degrees other way |
aismail1997 | 0:9eda4611081a | 38 | if (pb1 == 1 && state == 1) { |
aismail1997 | 0:9eda4611081a | 39 | while(pb1 == 1) |
aismail1997 | 0:9eda4611081a | 40 | myled = 0; |
aismail1997 | 0:9eda4611081a | 41 | for(int i=7; i>3; i--) { |
aismail1997 | 0:9eda4611081a | 42 | myservo = i/100.0; |
aismail1997 | 0:9eda4611081a | 43 | wait(0.01); |
aismail1997 | 0:9eda4611081a | 44 | } |
aismail1997 | 0:9eda4611081a | 45 | //wait(0.1); |
aismail1997 | 0:9eda4611081a | 46 | state = 2; |
aismail1997 | 0:9eda4611081a | 47 | } |
aismail1997 | 0:9eda4611081a | 48 | //wait(1.0); |
aismail1997 | 0:9eda4611081a | 49 | |
aismail1997 | 0:9eda4611081a | 50 | // read linear potentiometer |
aismail1997 | 0:9eda4611081a | 51 | //if (linpot < 0.5) { |
aismail1997 | 0:9eda4611081a | 52 | //float potval = linpot; |
aismail1997 | 0:9eda4611081a | 53 | //pc.printf("linear pot: %f\n", potval); |
aismail1997 | 0:9eda4611081a | 54 | } |
aismail1997 | 0:9eda4611081a | 55 | } |