idd hw3
Dependencies: mbed DebounceIn USBDevice PinDetect
main.cpp@2:4b2e3ca87deb, 2014-09-26 (annotated)
- Committer:
- emilychen55
- Date:
- Fri Sep 26 19:21:07 2014 +0000
- Revision:
- 2:4b2e3ca87deb
- Parent:
- 1:85b6b5d1528e
- Child:
- 4:c90291fd6cc9
publishing idd_hw3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pgao | 0:84cb4cb4f860 | 1 | #include "mbed.h" |
emilychen55 | 1:85b6b5d1528e | 2 | #include "USBMouseKeyboard.h" |
emilychen55 | 1:85b6b5d1528e | 3 | #include "DebounceIn.h" |
emilychen55 | 1:85b6b5d1528e | 4 | |
emilychen55 | 1:85b6b5d1528e | 5 | //LED1: NUM_LOCK |
emilychen55 | 1:85b6b5d1528e | 6 | //LED2: CAPS_LOCK |
emilychen55 | 1:85b6b5d1528e | 7 | //LED3: SCROLL_LOCK |
emilychen55 | 2:4b2e3ca87deb | 8 | BusOut leds(LED1, LED2, LED3); |
emilychen55 | 1:85b6b5d1528e | 9 | DebounceIn accelerate(D7); |
emilychen55 | 1:85b6b5d1528e | 10 | DigitalIn powerUp(D13); |
emilychen55 | 1:85b6b5d1528e | 11 | DigitalIn breakz(D6); |
pgao | 0:84cb4cb4f860 | 12 | |
pgao | 0:84cb4cb4f860 | 13 | Serial pc(USBTX, USBRX); |
pgao | 0:84cb4cb4f860 | 14 | |
pgao | 0:84cb4cb4f860 | 15 | AnalogIn accelZ(A0); |
pgao | 0:84cb4cb4f860 | 16 | AnalogIn accelY(A1); |
pgao | 0:84cb4cb4f860 | 17 | AnalogIn accelX(A2); |
emilychen55 | 1:85b6b5d1528e | 18 | |
emilychen55 | 1:85b6b5d1528e | 19 | //USBMouseKeyboard |
emilychen55 | 2:4b2e3ca87deb | 20 | USBMouseKeyboard controller; |
pgao | 0:84cb4cb4f860 | 21 | |
emilychen55 | 1:85b6b5d1528e | 22 | //Y: 0.43 - 0.56 |
emilychen55 | 1:85b6b5d1528e | 23 | //X: 0.39 - 0.57 |
emilychen55 | 1:85b6b5d1528e | 24 | float CENTER_LEFT = 0.48; |
emilychen55 | 1:85b6b5d1528e | 25 | float CENTER_RIGHT = 0.51; |
emilychen55 | 1:85b6b5d1528e | 26 | float CENTER_UP = 0.43; |
emilychen55 | 1:85b6b5d1528e | 27 | float CENTER_DOWN = 0.53; |
emilychen55 | 1:85b6b5d1528e | 28 | |
emilychen55 | 1:85b6b5d1528e | 29 | int main(void) { |
emilychen55 | 1:85b6b5d1528e | 30 | pc.baud(115200); |
emilychen55 | 1:85b6b5d1528e | 31 | while (1) { |
emilychen55 | 2:4b2e3ca87deb | 32 | if (!accelerate) { |
emilychen55 | 2:4b2e3ca87deb | 33 | controller.keyCode('x'); |
emilychen55 | 2:4b2e3ca87deb | 34 | if (accelY.read() <= CENTER_LEFT) { |
emilychen55 | 2:4b2e3ca87deb | 35 | //controller.move(-1, 0); |
emilychen55 | 2:4b2e3ca87deb | 36 | controller.keyCode(LEFT_ARROW); |
emilychen55 | 2:4b2e3ca87deb | 37 | controller.keyCode('x'); |
emilychen55 | 2:4b2e3ca87deb | 38 | } |
emilychen55 | 2:4b2e3ca87deb | 39 | if (accelY.read() >= CENTER_RIGHT) { |
emilychen55 | 2:4b2e3ca87deb | 40 | //controller.move(1, 0); |
emilychen55 | 2:4b2e3ca87deb | 41 | controller.keyCode(RIGHT_ARROW); |
emilychen55 | 2:4b2e3ca87deb | 42 | controller.keyCode('x'); |
emilychen55 | 2:4b2e3ca87deb | 43 | } |
emilychen55 | 2:4b2e3ca87deb | 44 | } |
emilychen55 | 2:4b2e3ca87deb | 45 | if (!powerUp) { |
emilychen55 | 2:4b2e3ca87deb | 46 | controller.keyCode('x'); |
emilychen55 | 2:4b2e3ca87deb | 47 | controller.keyCode('s'); |
emilychen55 | 2:4b2e3ca87deb | 48 | controller.keyCode('x'); |
emilychen55 | 2:4b2e3ca87deb | 49 | } |
emilychen55 | 2:4b2e3ca87deb | 50 | if (!breakz) { |
emilychen55 | 2:4b2e3ca87deb | 51 | controller.keyCode('z'); |
emilychen55 | 2:4b2e3ca87deb | 52 | } |
emilychen55 | 2:4b2e3ca87deb | 53 | // Navigation in Game Menu |
emilychen55 | 1:85b6b5d1528e | 54 | if (accelY.read() <= CENTER_LEFT) { |
emilychen55 | 2:4b2e3ca87deb | 55 | controller.keyCode(LEFT_ARROW); |
emilychen55 | 1:85b6b5d1528e | 56 | } |
emilychen55 | 1:85b6b5d1528e | 57 | if (accelY.read() >= CENTER_RIGHT) { |
emilychen55 | 2:4b2e3ca87deb | 58 | controller.keyCode(RIGHT_ARROW); |
emilychen55 | 1:85b6b5d1528e | 59 | } |
emilychen55 | 1:85b6b5d1528e | 60 | if (accelX.read() <= CENTER_UP) { |
emilychen55 | 2:4b2e3ca87deb | 61 | controller.keyCode(UP_ARROW); |
emilychen55 | 2:4b2e3ca87deb | 62 | wait(0.1); |
emilychen55 | 1:85b6b5d1528e | 63 | } |
emilychen55 | 1:85b6b5d1528e | 64 | if (accelX.read() >= CENTER_DOWN) { |
emilychen55 | 2:4b2e3ca87deb | 65 | controller.keyCode(DOWN_ARROW); |
emilychen55 | 2:4b2e3ca87deb | 66 | wait(0.1); |
emilychen55 | 1:85b6b5d1528e | 67 | } |
pgao | 0:84cb4cb4f860 | 68 | } |
emilychen55 | 1:85b6b5d1528e | 69 | } |