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