idd hw3

Dependencies:   mbed DebounceIn USBDevice PinDetect

Committer:
pgao
Date:
Fri Sep 26 20:46:47 2014 +0000
Revision:
4:c90291fd6cc9
Parent:
2:4b2e3ca87deb
Child:
6:adec77323ab2
digitalin to debouncein

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pgao 0:84cb4cb4f860 1 #include "mbed.h"
emilychen55 1:85b6b5d1528e 2 #include "USBMouseKeyboard.h"
emilychen55 1:85b6b5d1528e 3 #include "DebounceIn.h"
pgao 4:c90291fd6cc9 4
emilychen55 2:4b2e3ca87deb 5 BusOut leds(LED1, LED2, LED3);
emilychen55 1:85b6b5d1528e 6 DebounceIn accelerate(D7);
pgao 4:c90291fd6cc9 7 DebounceIn powerUp(D13);
pgao 4:c90291fd6cc9 8 DebounceIn breakz(D6);
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
emilychen55 2:4b2e3ca87deb 17 USBMouseKeyboard controller;
pgao 0:84cb4cb4f860 18
emilychen55 1:85b6b5d1528e 19 //Y: 0.43 - 0.56
emilychen55 1:85b6b5d1528e 20 //X: 0.39 - 0.57
emilychen55 1:85b6b5d1528e 21 float CENTER_LEFT = 0.48;
emilychen55 1:85b6b5d1528e 22 float CENTER_RIGHT = 0.51;
emilychen55 1:85b6b5d1528e 23 float CENTER_UP = 0.43;
emilychen55 1:85b6b5d1528e 24 float CENTER_DOWN = 0.53;
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) {
emilychen55 2:4b2e3ca87deb 30 controller.keyCode('x');
emilychen55 2:4b2e3ca87deb 31 if (accelY.read() <= CENTER_LEFT) {
emilychen55 2:4b2e3ca87deb 32 //controller.move(-1, 0);
emilychen55 2:4b2e3ca87deb 33 controller.keyCode(LEFT_ARROW);
emilychen55 2:4b2e3ca87deb 34 controller.keyCode('x');
emilychen55 2:4b2e3ca87deb 35 }
emilychen55 2:4b2e3ca87deb 36 if (accelY.read() >= CENTER_RIGHT) {
emilychen55 2:4b2e3ca87deb 37 //controller.move(1, 0);
emilychen55 2:4b2e3ca87deb 38 controller.keyCode(RIGHT_ARROW);
emilychen55 2:4b2e3ca87deb 39 controller.keyCode('x');
emilychen55 2:4b2e3ca87deb 40 }
emilychen55 2:4b2e3ca87deb 41 }
emilychen55 2:4b2e3ca87deb 42 if (!powerUp) {
emilychen55 2:4b2e3ca87deb 43 controller.keyCode('x');
emilychen55 2:4b2e3ca87deb 44 controller.keyCode('s');
emilychen55 2:4b2e3ca87deb 45 controller.keyCode('x');
emilychen55 2:4b2e3ca87deb 46 }
emilychen55 2:4b2e3ca87deb 47 if (!breakz) {
emilychen55 2:4b2e3ca87deb 48 controller.keyCode('z');
emilychen55 2:4b2e3ca87deb 49 }
emilychen55 2:4b2e3ca87deb 50 // Navigation in Game Menu
emilychen55 1:85b6b5d1528e 51 if (accelY.read() <= CENTER_LEFT) {
emilychen55 2:4b2e3ca87deb 52 controller.keyCode(LEFT_ARROW);
emilychen55 1:85b6b5d1528e 53 }
emilychen55 1:85b6b5d1528e 54 if (accelY.read() >= CENTER_RIGHT) {
emilychen55 2:4b2e3ca87deb 55 controller.keyCode(RIGHT_ARROW);
emilychen55 1:85b6b5d1528e 56 }
emilychen55 1:85b6b5d1528e 57 if (accelX.read() <= CENTER_UP) {
emilychen55 2:4b2e3ca87deb 58 controller.keyCode(UP_ARROW);
emilychen55 2:4b2e3ca87deb 59 wait(0.1);
emilychen55 1:85b6b5d1528e 60 }
emilychen55 1:85b6b5d1528e 61 if (accelX.read() >= CENTER_DOWN) {
emilychen55 2:4b2e3ca87deb 62 controller.keyCode(DOWN_ARROW);
emilychen55 2:4b2e3ca87deb 63 wait(0.1);
emilychen55 1:85b6b5d1528e 64 }
pgao 0:84cb4cb4f860 65 }
emilychen55 1:85b6b5d1528e 66 }