idd hw3
Dependencies: mbed DebounceIn USBDevice PinDetect
Diff: main.cpp
- Revision:
- 6:adec77323ab2
- Parent:
- 4:c90291fd6cc9
- Child:
- 7:7abb32ab30b6
diff -r ed21c36da5c5 -r adec77323ab2 main.cpp --- a/main.cpp Fri Sep 26 20:48:23 2014 +0000 +++ b/main.cpp Sun Sep 28 21:56:04 2014 +0000 @@ -1,5 +1,5 @@ #include "mbed.h" -#include "USBMouseKeyboard.h" +#include "USBKeyboard.h" #include "DebounceIn.h" BusOut leds(LED1, LED2, LED3); @@ -14,52 +14,58 @@ AnalogIn accelX(A2); //USBMouseKeyboard -USBMouseKeyboard controller; +//USBKeyboard controller; //Y: 0.43 - 0.56 //X: 0.39 - 0.57 float CENTER_LEFT = 0.48; float CENTER_RIGHT = 0.51; -float CENTER_UP = 0.43; -float CENTER_DOWN = 0.53; +float CENTER_UP = 0.47; +float CENTER_DOWN = 0.57; int main(void) { pc.baud(115200); while (1) { if (!accelerate) { - controller.keyCode('x'); - if (accelY.read() <= CENTER_LEFT) { +// controller.keyCode('x'); + if (accelX.read() <= CENTER_LEFT) { //controller.move(-1, 0); - controller.keyCode(LEFT_ARROW); - controller.keyCode('x'); +// controller.keyCode(LEFT_ARROW); +// controller.keyCode('x'); } - if (accelY.read() >= CENTER_RIGHT) { + if (accelX.read() >= CENTER_RIGHT) { //controller.move(1, 0); - controller.keyCode(RIGHT_ARROW); - controller.keyCode('x'); +// controller.keyCode(RIGHT_ARROW); +// controller.keyCode('x'); } } if (!powerUp) { - controller.keyCode('x'); - controller.keyCode('s'); - controller.keyCode('x'); +// controller.keyCode('x'); +// controller.keyCode('s'); +// controller.keyCode('x'); } if (!breakz) { - controller.keyCode('z'); +// controller.keyCode('z'); } // Navigation in Game Menu - if (accelY.read() <= CENTER_LEFT) { - controller.keyCode(LEFT_ARROW); - } - if (accelY.read() >= CENTER_RIGHT) { - controller.keyCode(RIGHT_ARROW); - } - if (accelX.read() <= CENTER_UP) { - controller.keyCode(UP_ARROW); + if (accelX.read() <= CENTER_LEFT) { +// controller.keyCode(LEFT_ARROW); + pc.printf("left\n"); wait(0.1); } - if (accelX.read() >= CENTER_DOWN) { - controller.keyCode(DOWN_ARROW); + if (accelX.read() >= CENTER_RIGHT) { +// controller.keyCode(RIGHT_ARROW); + pc.printf("right\n"); + wait(0.1); + } + if (accelZ.read() <= CENTER_UP) { +// controller.keyCode(UP_ARROW); + pc.printf("up\n"); + wait(0.1); + } + if (accelZ.read() >= CENTER_DOWN) { +// controller.keyCode(DOWN_ARROW); + pc.printf("down\n"); wait(0.1); } }