idd hw3
Dependencies: mbed DebounceIn USBDevice PinDetect
main.cpp@1:85b6b5d1528e, 2014-09-26 (annotated)
- Committer:
- emilychen55
- Date:
- Fri Sep 26 17:05:33 2014 +0000
- Revision:
- 1:85b6b5d1528e
- Parent:
- 0:84cb4cb4f860
- Child:
- 2:4b2e3ca87deb
updated hw3 code with added libraries (DebounceIn and USBDevice)
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 | 1:85b6b5d1528e | 8 | BusOut leds(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 | 1:85b6b5d1528e | 20 | USBMouseKeyboard key_mouse; |
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 | // debouncing |
emilychen55 | 1:85b6b5d1528e | 30 | |
emilychen55 | 1:85b6b5d1528e | 31 | int main(void) { |
emilychen55 | 1:85b6b5d1528e | 32 | pc.baud(115200); |
emilychen55 | 1:85b6b5d1528e | 33 | while (1) { |
emilychen55 | 1:85b6b5d1528e | 34 | if (accelY.read() <= CENTER_LEFT) { |
emilychen55 | 1:85b6b5d1528e | 35 | //key_mouse.move(-1, 0); |
emilychen55 | 1:85b6b5d1528e | 36 | key_mouse.keyCode(LEFT_ARROW); |
emilychen55 | 1:85b6b5d1528e | 37 | } |
emilychen55 | 1:85b6b5d1528e | 38 | if (accelY.read() >= CENTER_RIGHT) { |
emilychen55 | 1:85b6b5d1528e | 39 | //key_mouse.move(1, 0); |
emilychen55 | 1:85b6b5d1528e | 40 | key_mouse.keyCode(RIGHT_ARROW); |
emilychen55 | 1:85b6b5d1528e | 41 | } |
emilychen55 | 1:85b6b5d1528e | 42 | if (accelX.read() <= CENTER_UP) { |
emilychen55 | 1:85b6b5d1528e | 43 | key_mouse.keyCode(UP_ARROW); |
emilychen55 | 1:85b6b5d1528e | 44 | } |
emilychen55 | 1:85b6b5d1528e | 45 | if (accelX.read() >= CENTER_DOWN) { |
emilychen55 | 1:85b6b5d1528e | 46 | key_mouse.keyCode(DOWN_ARROW); |
emilychen55 | 1:85b6b5d1528e | 47 | } |
emilychen55 | 1:85b6b5d1528e | 48 | if (accelerate == 0) { |
emilychen55 | 1:85b6b5d1528e | 49 | key_mouse.keyCode('x'); |
emilychen55 | 1:85b6b5d1528e | 50 | } |
emilychen55 | 1:85b6b5d1528e | 51 | if (powerUp == 0) { |
emilychen55 | 1:85b6b5d1528e | 52 | key_mouse.keyCode('s'); |
emilychen55 | 1:85b6b5d1528e | 53 | } |
emilychen55 | 1:85b6b5d1528e | 54 | if (breakz == 0) { |
emilychen55 | 1:85b6b5d1528e | 55 | key_mouse.keyCode('z'); |
emilychen55 | 1:85b6b5d1528e | 56 | } |
pgao | 0:84cb4cb4f860 | 57 | } |
emilychen55 | 1:85b6b5d1528e | 58 | } |