idd hw3
Dependencies: mbed DebounceIn USBDevice PinDetect
Diff: main.cpp
- Revision:
- 1:85b6b5d1528e
- Parent:
- 0:84cb4cb4f860
- Child:
- 2:4b2e3ca87deb
--- a/main.cpp Fri Sep 26 00:23:26 2014 +0000 +++ b/main.cpp Fri Sep 26 17:05:33 2014 +0000 @@ -1,13 +1,58 @@ #include "mbed.h" +#include "USBMouseKeyboard.h" +#include "DebounceIn.h" + +//LED1: NUM_LOCK +//LED2: CAPS_LOCK +//LED3: SCROLL_LOCK +BusOut leds(LED3); +DebounceIn accelerate(D7); +DigitalIn powerUp(D13); +DigitalIn breakz(D6); Serial pc(USBTX, USBRX); AnalogIn accelZ(A0); AnalogIn accelY(A1); AnalogIn accelX(A2); + +//USBMouseKeyboard +USBMouseKeyboard key_mouse; -int main() { - while(1) { - pc.printf("%f\n", accelY.read()); +//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; + +// debouncing + +int main(void) { + pc.baud(115200); + while (1) { + if (accelY.read() <= CENTER_LEFT) { + //key_mouse.move(-1, 0); + key_mouse.keyCode(LEFT_ARROW); + } + if (accelY.read() >= CENTER_RIGHT) { + //key_mouse.move(1, 0); + key_mouse.keyCode(RIGHT_ARROW); + } + if (accelX.read() <= CENTER_UP) { + key_mouse.keyCode(UP_ARROW); + } + if (accelX.read() >= CENTER_DOWN) { + key_mouse.keyCode(DOWN_ARROW); + } + if (accelerate == 0) { + key_mouse.keyCode('x'); + } + if (powerUp == 0) { + key_mouse.keyCode('s'); + } + if (breakz == 0) { + key_mouse.keyCode('z'); + } } -} +} \ No newline at end of file