idd hw3

Dependencies:   mbed DebounceIn USBDevice PinDetect

Committer:
pgao
Date:
Sun Sep 28 22:02:27 2014 +0000
Revision:
7:7abb32ab30b6
Parent:
6:adec77323ab2
Child:
8:a6ff9fbacf85
restore keycode commands

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pgao 0:84cb4cb4f860 1 #include "mbed.h"
pgao 6:adec77323ab2 2 #include "USBKeyboard.h"
emilychen55 1:85b6b5d1528e 3 #include "DebounceIn.h"
pgao 4:c90291fd6cc9 4
emilychen55 2:4b2e3ca87deb 5 BusOut leds(LED1, LED2, LED3);
pgao 7:7abb32ab30b6 6 DebounceIn accelerate(D11);
pgao 7:7abb32ab30b6 7 DebounceIn powerUp(D10);
pgao 7:7abb32ab30b6 8 DebounceIn breakz(D13);
pgao 0:84cb4cb4f860 9
pgao 0:84cb4cb4f860 10 Serial pc(USBTX, USBRX);
pgao 0:84cb4cb4f860 11
pgao 0:84cb4cb4f860 12 AnalogIn accelZ(A0);
pgao 0:84cb4cb4f860 13 AnalogIn accelY(A1);
pgao 0:84cb4cb4f860 14 AnalogIn accelX(A2);
emilychen55 1:85b6b5d1528e 15
emilychen55 1:85b6b5d1528e 16 //USBMouseKeyboard
pgao 7:7abb32ab30b6 17 USBKeyboard controller;
pgao 0:84cb4cb4f860 18
pgao 7:7abb32ab30b6 19 //X: 0.48 - 0.51
pgao 7:7abb32ab30b6 20 //Z: 0.47 - 0.57
emilychen55 1:85b6b5d1528e 21 float CENTER_LEFT = 0.48;
emilychen55 1:85b6b5d1528e 22 float CENTER_RIGHT = 0.51;
pgao 6:adec77323ab2 23 float CENTER_UP = 0.47;
pgao 6:adec77323ab2 24 float CENTER_DOWN = 0.57;
emilychen55 1:85b6b5d1528e 25
emilychen55 1:85b6b5d1528e 26 int main(void) {
emilychen55 1:85b6b5d1528e 27 pc.baud(115200);
emilychen55 1:85b6b5d1528e 28 while (1) {
emilychen55 2:4b2e3ca87deb 29 if (!accelerate) {
pgao 7:7abb32ab30b6 30 controller.keyCode('x');
pgao 6:adec77323ab2 31 if (accelX.read() <= CENTER_LEFT) {
emilychen55 2:4b2e3ca87deb 32 //controller.move(-1, 0);
pgao 7:7abb32ab30b6 33 controller.keyCode(LEFT_ARROW);
pgao 7:7abb32ab30b6 34 controller.keyCode('x');
emilychen55 2:4b2e3ca87deb 35 }
pgao 6:adec77323ab2 36 if (accelX.read() >= CENTER_RIGHT) {
emilychen55 2:4b2e3ca87deb 37 //controller.move(1, 0);
pgao 7:7abb32ab30b6 38 controller.keyCode(RIGHT_ARROW);
pgao 7:7abb32ab30b6 39 controller.keyCode('x');
emilychen55 2:4b2e3ca87deb 40 }
emilychen55 2:4b2e3ca87deb 41 }
emilychen55 2:4b2e3ca87deb 42 if (!powerUp) {
pgao 7:7abb32ab30b6 43 controller.keyCode('x');
pgao 7:7abb32ab30b6 44 controller.keyCode('s');
pgao 7:7abb32ab30b6 45 controller.keyCode('x');
emilychen55 2:4b2e3ca87deb 46 }
emilychen55 2:4b2e3ca87deb 47 if (!breakz) {
pgao 7:7abb32ab30b6 48 controller.keyCode('z');
emilychen55 2:4b2e3ca87deb 49 }
emilychen55 2:4b2e3ca87deb 50 // Navigation in Game Menu
pgao 6:adec77323ab2 51 if (accelX.read() <= CENTER_LEFT) {
pgao 7:7abb32ab30b6 52 controller.keyCode(LEFT_ARROW);
pgao 6:adec77323ab2 53 pc.printf("left\n");
emilychen55 2:4b2e3ca87deb 54 wait(0.1);
emilychen55 1:85b6b5d1528e 55 }
pgao 6:adec77323ab2 56 if (accelX.read() >= CENTER_RIGHT) {
pgao 7:7abb32ab30b6 57 controller.keyCode(RIGHT_ARROW);
pgao 6:adec77323ab2 58 pc.printf("right\n");
pgao 6:adec77323ab2 59 wait(0.1);
pgao 6:adec77323ab2 60 }
pgao 6:adec77323ab2 61 if (accelZ.read() <= CENTER_UP) {
pgao 7:7abb32ab30b6 62 controller.keyCode(UP_ARROW);
pgao 6:adec77323ab2 63 pc.printf("up\n");
pgao 6:adec77323ab2 64 wait(0.1);
pgao 6:adec77323ab2 65 }
pgao 6:adec77323ab2 66 if (accelZ.read() >= CENTER_DOWN) {
pgao 7:7abb32ab30b6 67 controller.keyCode(DOWN_ARROW);
pgao 6:adec77323ab2 68 pc.printf("down\n");
emilychen55 2:4b2e3ca87deb 69 wait(0.1);
emilychen55 1:85b6b5d1528e 70 }
pgao 0:84cb4cb4f860 71 }
emilychen55 1:85b6b5d1528e 72 }