sword
Dependencies: mbed PinDetect_KL25Z USBDevice
main.cpp@3:0251fef04954, 2015-09-20 (annotated)
- Committer:
- twuster
- Date:
- Sun Sep 20 22:21:33 2015 +0000
- Revision:
- 3:0251fef04954
- Parent:
- 2:082bca930f40
sword swinging works
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
twuster | 0:8c7c6ac65e1a | 1 | #include "mbed.h" |
twuster | 2:082bca930f40 | 2 | #include "PinDetect.h" |
twuster | 2:082bca930f40 | 3 | #include "USBKeyboard.h" |
twuster | 2:082bca930f40 | 4 | |
twuster | 3:0251fef04954 | 5 | //Serial pc(USBTX, USBRX); |
twuster | 0:8c7c6ac65e1a | 6 | |
twuster | 2:082bca930f40 | 7 | AnalogIn x_in(A0); |
twuster | 2:082bca930f40 | 8 | AnalogIn y_in(A1); |
twuster | 2:082bca930f40 | 9 | AnalogIn z_in(A2); |
twuster | 2:082bca930f40 | 10 | |
twuster | 3:0251fef04954 | 11 | USBKeyboard keyboard; |
twuster | 2:082bca930f40 | 12 | PinDetect start_button(D6); |
twuster | 2:082bca930f40 | 13 | PinDetect up_button(D5); |
twuster | 2:082bca930f40 | 14 | PinDetect down_button(D4); |
twuster | 2:082bca930f40 | 15 | PinDetect right_button(D8); |
twuster | 2:082bca930f40 | 16 | PinDetect left_button(D7); |
twuster | 3:0251fef04954 | 17 | PinDetect a_button(D9); |
twuster | 0:8c7c6ac65e1a | 18 | |
twuster | 0:8c7c6ac65e1a | 19 | int main() { |
twuster | 2:082bca930f40 | 20 | start_button.mode(PullUp); |
twuster | 2:082bca930f40 | 21 | up_button.mode(PullUp); |
twuster | 2:082bca930f40 | 22 | down_button.mode(PullUp); |
twuster | 2:082bca930f40 | 23 | right_button.mode(PullUp); |
twuster | 2:082bca930f40 | 24 | left_button.mode(PullUp); |
twuster | 2:082bca930f40 | 25 | |
twuster | 0:8c7c6ac65e1a | 26 | while(1) { |
twuster | 3:0251fef04954 | 27 | |
twuster | 3:0251fef04954 | 28 | if (x_in.read() > .8 || y_in.read() > .8 || z_in.read() > .8) { |
twuster | 3:0251fef04954 | 29 | keyboard.printf("%s", "a"); |
twuster | 3:0251fef04954 | 30 | } else if (start_button == 0) { |
twuster | 2:082bca930f40 | 31 | keyboard.keyCode(32); |
twuster | 2:082bca930f40 | 32 | } else if (up_button == 0) { |
twuster | 3:0251fef04954 | 33 | keyboard.keyCode(UP_ARROW); |
twuster | 2:082bca930f40 | 34 | } else if (down_button == 0) { |
twuster | 3:0251fef04954 | 35 | keyboard.keyCode(DOWN_ARROW); |
twuster | 2:082bca930f40 | 36 | } else if (right_button == 0) { |
twuster | 3:0251fef04954 | 37 | keyboard.keyCode(RIGHT_ARROW); |
twuster | 2:082bca930f40 | 38 | } else if (left_button == 0) { |
twuster | 3:0251fef04954 | 39 | keyboard.keyCode(LEFT_ARROW); |
twuster | 3:0251fef04954 | 40 | } else if (a_button ==0) { |
twuster | 3:0251fef04954 | 41 | keyboard.printf("%s", "a"); |
twuster | 3:0251fef04954 | 42 | } |
twuster | 0:8c7c6ac65e1a | 43 | } |
twuster | 0:8c7c6ac65e1a | 44 | } |