idd hw3
Dependencies: mbed DebounceIn USBDevice PinDetect
main.cpp
- Committer:
- pgao
- Date:
- 2014-09-28
- Revision:
- 6:adec77323ab2
- Parent:
- 4:c90291fd6cc9
- Child:
- 7:7abb32ab30b6
File content as of revision 6:adec77323ab2:
#include "mbed.h" #include "USBKeyboard.h" #include "DebounceIn.h" BusOut leds(LED1, LED2, LED3); DebounceIn accelerate(D7); DebounceIn powerUp(D13); DebounceIn breakz(D6); Serial pc(USBTX, USBRX); AnalogIn accelZ(A0); AnalogIn accelY(A1); AnalogIn accelX(A2); //USBMouseKeyboard //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.47; float CENTER_DOWN = 0.57; int main(void) { pc.baud(115200); while (1) { if (!accelerate) { // controller.keyCode('x'); if (accelX.read() <= CENTER_LEFT) { //controller.move(-1, 0); // controller.keyCode(LEFT_ARROW); // controller.keyCode('x'); } if (accelX.read() >= CENTER_RIGHT) { //controller.move(1, 0); // controller.keyCode(RIGHT_ARROW); // controller.keyCode('x'); } } if (!powerUp) { // controller.keyCode('x'); // controller.keyCode('s'); // controller.keyCode('x'); } if (!breakz) { // controller.keyCode('z'); } // Navigation in Game Menu if (accelX.read() <= CENTER_LEFT) { // controller.keyCode(LEFT_ARROW); pc.printf("left\n"); wait(0.1); } 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); } } }