![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
wheelchair code for alexa integration
Fork of wheelchaircontrol by
main.cpp@12:3cf6376007c6, 2018-08-17 (annotated)
- Committer:
- ryanlin97
- Date:
- Fri Aug 17 03:12:21 2018 +0000
- Revision:
- 12:3cf6376007c6
- Parent:
- 11:75f0f13ff6c1
alexa code
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 | 12:3cf6376007c6 | 6 | DigitalOut on(D12); |
ryanlin97 | 12:3cf6376007c6 | 7 | DigitalOut off(D11); |
ryanlin97 | 0:fc0c4a184482 | 8 | DigitalOut up(D2); |
ryanlin97 | 0:fc0c4a184482 | 9 | DigitalOut down(D3); |
ryanlin97 | 2:c2d049efc266 | 10 | |
ryanlin97 | 10:e5463c11e0a0 | 11 | bool manual = false; |
ryanlin97 | 10:e5463c11e0a0 | 12 | |
ryanlin97 | 12:3cf6376007c6 | 13 | Serial pc(USBTX, USBRX, 9600); |
ryanlin97 | 7:5e38d43fbce3 | 14 | Timer t; |
ryanlin97 | 6:0cd57bdd8fbc | 15 | |
ryanlin97 | 11:75f0f13ff6c1 | 16 | Wheelchair smart(xDir,yDir, &pc, &t); |
ryanlin97 | 11:75f0f13ff6c1 | 17 | |
ryanlin97 | 12:3cf6376007c6 | 18 | char c = 'z'; |
ryanlin97 | 2:c2d049efc266 | 19 | |
ryanlin97 | 0:fc0c4a184482 | 20 | int main(void) |
ryanlin97 | 0:fc0c4a184482 | 21 | { |
ryanlin97 | 6:0cd57bdd8fbc | 22 | while(1) { |
ryanlin97 | 10:e5463c11e0a0 | 23 | if( pc.readable()) { |
ryanlin97 | 12:3cf6376007c6 | 24 | c = pc.getc(); |
ryanlin97 | 12:3cf6376007c6 | 25 | } |
ryanlin97 | 12:3cf6376007c6 | 26 | |
ryanlin97 | 12:3cf6376007c6 | 27 | else { |
ryanlin97 | 10:e5463c11e0a0 | 28 | if( c == 'w') { |
ryanlin97 | 10:e5463c11e0a0 | 29 | pc.printf("up \n"); |
ryanlin97 | 10:e5463c11e0a0 | 30 | smart.forward(); |
ryanlin97 | 10:e5463c11e0a0 | 31 | } |
ryanlin97 | 6:0cd57bdd8fbc | 32 | |
ryanlin97 | 11:75f0f13ff6c1 | 33 | else if( c == 'a') { |
ryanlin97 | 10:e5463c11e0a0 | 34 | pc.printf("left \n"); |
ryanlin97 | 10:e5463c11e0a0 | 35 | smart.left(); |
ryanlin97 | 10:e5463c11e0a0 | 36 | } |
ryanlin97 | 6:0cd57bdd8fbc | 37 | |
ryanlin97 | 11:75f0f13ff6c1 | 38 | else if( c == 'd') { |
ryanlin97 | 10:e5463c11e0a0 | 39 | pc.printf("right \n"); |
ryanlin97 | 10:e5463c11e0a0 | 40 | smart.right(); |
ryanlin97 | 10:e5463c11e0a0 | 41 | } |
ryanlin97 | 6:0cd57bdd8fbc | 42 | |
ryanlin97 | 10:e5463c11e0a0 | 43 | else if( c == 's') { |
ryanlin97 | 10:e5463c11e0a0 | 44 | pc.printf("down \n"); |
ryanlin97 | 10:e5463c11e0a0 | 45 | smart.backward(); |
ryanlin97 | 10:e5463c11e0a0 | 46 | } |
ryanlin97 | 6:0cd57bdd8fbc | 47 | |
ryanlin97 | 10:e5463c11e0a0 | 48 | else if( c == 'r') { |
ryanlin97 | 11:75f0f13ff6c1 | 49 | smart.turn_right(90); |
ryanlin97 | 10:e5463c11e0a0 | 50 | } |
ryanlin97 | 6:0cd57bdd8fbc | 51 | |
ryanlin97 | 10:e5463c11e0a0 | 52 | else if( c == 'l') { |
ryanlin97 | 11:75f0f13ff6c1 | 53 | smart.turn_left(90); |
ryanlin97 | 10:e5463c11e0a0 | 54 | } |
ryanlin97 | 12:3cf6376007c6 | 55 | else if(c == 'o') { |
ryanlin97 | 12:3cf6376007c6 | 56 | pc.printf("turning on\n"); |
ryanlin97 | 12:3cf6376007c6 | 57 | on = 1; |
ryanlin97 | 12:3cf6376007c6 | 58 | wait(1); |
ryanlin97 | 12:3cf6376007c6 | 59 | on = 0; |
ryanlin97 | 12:3cf6376007c6 | 60 | c = 'z'; |
ryanlin97 | 12:3cf6376007c6 | 61 | } else if(c == 'f') { |
ryanlin97 | 12:3cf6376007c6 | 62 | pc.printf("turning off\n"); |
ryanlin97 | 12:3cf6376007c6 | 63 | off = 1; |
ryanlin97 | 12:3cf6376007c6 | 64 | wait(1); |
ryanlin97 | 12:3cf6376007c6 | 65 | off = 0; |
ryanlin97 | 12:3cf6376007c6 | 66 | c = 'z'; |
ryanlin97 | 12:3cf6376007c6 | 67 | } |
ryanlin97 | 6:0cd57bdd8fbc | 68 | |
ryanlin97 | 11:75f0f13ff6c1 | 69 | else if( c == 't') { |
ryanlin97 | 11:75f0f13ff6c1 | 70 | char buffer[256]; |
ryanlin97 | 11:75f0f13ff6c1 | 71 | pc.printf ("Enter a long number: "); |
ryanlin97 | 11:75f0f13ff6c1 | 72 | fgets (buffer, 256, stdin); |
ryanlin97 | 11:75f0f13ff6c1 | 73 | int angle = atoi (buffer); |
ryanlin97 | 12:3cf6376007c6 | 74 | |
ryanlin97 | 11:75f0f13ff6c1 | 75 | if(angle == 0) { |
ryanlin97 | 11:75f0f13ff6c1 | 76 | pc.printf("invalid input try again\n"); |
ryanlin97 | 12:3cf6376007c6 | 77 | } else { |
ryanlin97 | 12:3cf6376007c6 | 78 | smart.turn(angle); |
ryanlin97 | 12:3cf6376007c6 | 79 | } |
ryanlin97 | 12:3cf6376007c6 | 80 | |
ryanlin97 | 12:3cf6376007c6 | 81 | } |
ryanlin97 | 12:3cf6376007c6 | 82 | |
ryanlin97 | 11:75f0f13ff6c1 | 83 | else if( c == 'm') { |
ryanlin97 | 10:e5463c11e0a0 | 84 | pc.printf("turning on joystick\n"); |
ryanlin97 | 10:e5463c11e0a0 | 85 | manual = true; |
ryanlin97 | 11:75f0f13ff6c1 | 86 | t.reset(); |
ryanlin97 | 10:e5463c11e0a0 | 87 | while(manual) { |
ryanlin97 | 10:e5463c11e0a0 | 88 | smart.move(x,y); |
ryanlin97 | 10:e5463c11e0a0 | 89 | if( pc.readable()) { |
ryanlin97 | 10:e5463c11e0a0 | 90 | char d = pc.getc(); |
ryanlin97 | 10:e5463c11e0a0 | 91 | if( d == 'm') { |
ryanlin97 | 10:e5463c11e0a0 | 92 | pc.printf("turning off joystick\n"); |
ryanlin97 | 10:e5463c11e0a0 | 93 | manual = false; |
ryanlin97 | 10:e5463c11e0a0 | 94 | } |
ryanlin97 | 10:e5463c11e0a0 | 95 | } |
ryanlin97 | 10:e5463c11e0a0 | 96 | } |
ryanlin97 | 10:e5463c11e0a0 | 97 | } |
ryanlin97 | 6:0cd57bdd8fbc | 98 | |
ryanlin97 | 10:e5463c11e0a0 | 99 | else { |
ryanlin97 | 10:e5463c11e0a0 | 100 | smart.stop(); |
ryanlin97 | 12:3cf6376007c6 | 101 | pc.printf("hello\n"); |
ryanlin97 | 10:e5463c11e0a0 | 102 | } |
ryanlin97 | 10:e5463c11e0a0 | 103 | } |
ryanlin97 | 6:0cd57bdd8fbc | 104 | } |
ryanlin97 | 12:3cf6376007c6 | 105 | wait(process); |
ryanlin97 | 0:fc0c4a184482 | 106 | } |
ryanlin97 | 0:fc0c4a184482 | 107 | |
ryanlin97 | 12:3cf6376007c6 | 108 | |
ryanlin97 | 12:3cf6376007c6 | 109 |