![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Wheelchair control
Fork of wheelchaircontrol by
main.cpp@5:e0ccaab3959a, 2018-07-17 (annotated)
- Committer:
- ryanlin97
- Date:
- Tue Jul 17 07:19:04 2018 +0000
- Revision:
- 5:e0ccaab3959a
- Parent:
- 3:a5e71bfdb492
- Child:
- 6:8cd00c26bb47
imu added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ryanlin97 | 0:fc0c4a184482 | 1 | #include "wheelchair.h" |
ryanlin97 | 0:fc0c4a184482 | 2 | |
ryanlin97 | 3:a5e71bfdb492 | 3 | AnalogIn x(A0); |
ryanlin97 | 3:a5e71bfdb492 | 4 | AnalogIn y(A1); |
ryanlin97 | 3:a5e71bfdb492 | 5 | |
ryanlin97 | 0:fc0c4a184482 | 6 | DigitalOut off(D0); |
ryanlin97 | 0:fc0c4a184482 | 7 | DigitalOut on(D1); |
ryanlin97 | 0:fc0c4a184482 | 8 | DigitalOut up(D2); |
ryanlin97 | 0:fc0c4a184482 | 9 | DigitalOut down(D3); |
ryanlin97 | 2:c2d049efc266 | 10 | |
ryanlin97 | 2:c2d049efc266 | 11 | Wheelchair smart(xDir,yDir); |
ryanlin97 | 2:c2d049efc266 | 12 | |
ryanlin97 | 0:fc0c4a184482 | 13 | int main(void) |
ryanlin97 | 0:fc0c4a184482 | 14 | { |
ryanlin97 | 0:fc0c4a184482 | 15 | on = 1; |
ryanlin97 | 2:c2d049efc266 | 16 | while(1){ |
ryanlin97 | 3:a5e71bfdb492 | 17 | /* if( pc.readable()) { |
ryanlin97 | 2:c2d049efc266 | 18 | char c = pc.getc(); |
ryanlin97 | 2:c2d049efc266 | 19 | if( c == 'w') { |
ryanlin97 | 2:c2d049efc266 | 20 | pc.printf("up \n"); |
ryanlin97 | 2:c2d049efc266 | 21 | smart.forward(); |
ryanlin97 | 0:fc0c4a184482 | 22 | } |
ryanlin97 | 2:c2d049efc266 | 23 | |
ryanlin97 | 2:c2d049efc266 | 24 | else if( c == 'd') { |
ryanlin97 | 2:c2d049efc266 | 25 | pc.printf("left \n"); |
ryanlin97 | 2:c2d049efc266 | 26 | smart.left(); |
ryanlin97 | 0:fc0c4a184482 | 27 | } |
ryanlin97 | 2:c2d049efc266 | 28 | |
ryanlin97 | 2:c2d049efc266 | 29 | else if( c == 'a') { |
ryanlin97 | 2:c2d049efc266 | 30 | pc.printf("right \n"); |
ryanlin97 | 2:c2d049efc266 | 31 | smart.right(); |
ryanlin97 | 0:fc0c4a184482 | 32 | } |
ryanlin97 | 2:c2d049efc266 | 33 | |
ryanlin97 | 2:c2d049efc266 | 34 | else if( c == 's') { |
ryanlin97 | 2:c2d049efc266 | 35 | pc.printf("down \n"); |
ryanlin97 | 2:c2d049efc266 | 36 | smart.backward(); |
ryanlin97 | 0:fc0c4a184482 | 37 | } |
ryanlin97 | 2:c2d049efc266 | 38 | |
ryanlin97 | 2:c2d049efc266 | 39 | else { |
ryanlin97 | 2:c2d049efc266 | 40 | pc.printf("none \n"); |
ryanlin97 | 2:c2d049efc266 | 41 | smart.stop(); |
ryanlin97 | 2:c2d049efc266 | 42 | if( c == 'o') { |
ryanlin97 | 2:c2d049efc266 | 43 | pc.printf("turning on"); |
ryanlin97 | 2:c2d049efc266 | 44 | on = 0; |
ryanlin97 | 2:c2d049efc266 | 45 | wait(process); |
ryanlin97 | 2:c2d049efc266 | 46 | on = 1; |
ryanlin97 | 0:fc0c4a184482 | 47 | } |
ryanlin97 | 2:c2d049efc266 | 48 | |
ryanlin97 | 2:c2d049efc266 | 49 | else if( c == 'k') { |
ryanlin97 | 2:c2d049efc266 | 50 | off = 0; |
ryanlin97 | 2:c2d049efc266 | 51 | wait(process); |
ryanlin97 | 2:c2d049efc266 | 52 | off = 1; |
ryanlin97 | 0:fc0c4a184482 | 53 | } |
ryanlin97 | 2:c2d049efc266 | 54 | |
ryanlin97 | 2:c2d049efc266 | 55 | else if( c == 'u') { |
ryanlin97 | 2:c2d049efc266 | 56 | up = 0; |
ryanlin97 | 2:c2d049efc266 | 57 | wait(process); |
ryanlin97 | 2:c2d049efc266 | 58 | up = 1; |
ryanlin97 | 0:fc0c4a184482 | 59 | } |
ryanlin97 | 2:c2d049efc266 | 60 | |
ryanlin97 | 2:c2d049efc266 | 61 | else if( c == 'p') { |
ryanlin97 | 2:c2d049efc266 | 62 | down = 0; |
ryanlin97 | 2:c2d049efc266 | 63 | wait(process); |
ryanlin97 | 2:c2d049efc266 | 64 | down = 1; |
ryanlin97 | 0:fc0c4a184482 | 65 | } |
ryanlin97 | 0:fc0c4a184482 | 66 | } |
ryanlin97 | 2:c2d049efc266 | 67 | } |
ryanlin97 | 2:c2d049efc266 | 68 | |
ryanlin97 | 2:c2d049efc266 | 69 | else { |
ryanlin97 | 2:c2d049efc266 | 70 | pc.printf("Nothing pressed \n"); |
ryanlin97 | 2:c2d049efc266 | 71 | smart.stop(); |
ryanlin97 | 2:c2d049efc266 | 72 | } |
ryanlin97 | 3:a5e71bfdb492 | 73 | */ |
ryanlin97 | 3:a5e71bfdb492 | 74 | smart.move(x,y); |
ryanlin97 | 2:c2d049efc266 | 75 | wait(process); |
ryanlin97 | 2:c2d049efc266 | 76 | } |
ryanlin97 | 1:c0beadca1617 | 77 | |
ryanlin97 | 0:fc0c4a184482 | 78 | } |
ryanlin97 | 0:fc0c4a184482 | 79 |