idd hw3

Dependencies:   mbed DebounceIn USBDevice PinDetect

Committer:
pgao
Date:
Sun Sep 28 21:56:04 2014 +0000
Revision:
6:adec77323ab2
Parent:
4:c90291fd6cc9
Child:
7:7abb32ab30b6
remap accelerometer inputs for new mounting

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);
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
pgao 6:adec77323ab2 17 //USBKeyboard 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;
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 6:adec77323ab2 30 // controller.keyCode('x');
pgao 6:adec77323ab2 31 if (accelX.read() <= CENTER_LEFT) {
emilychen55 2:4b2e3ca87deb 32 //controller.move(-1, 0);
pgao 6:adec77323ab2 33 // controller.keyCode(LEFT_ARROW);
pgao 6:adec77323ab2 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 6:adec77323ab2 38 // controller.keyCode(RIGHT_ARROW);
pgao 6:adec77323ab2 39 // controller.keyCode('x');
emilychen55 2:4b2e3ca87deb 40 }
emilychen55 2:4b2e3ca87deb 41 }
emilychen55 2:4b2e3ca87deb 42 if (!powerUp) {
pgao 6:adec77323ab2 43 // controller.keyCode('x');
pgao 6:adec77323ab2 44 // controller.keyCode('s');
pgao 6:adec77323ab2 45 // controller.keyCode('x');
emilychen55 2:4b2e3ca87deb 46 }
emilychen55 2:4b2e3ca87deb 47 if (!breakz) {
pgao 6:adec77323ab2 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 6:adec77323ab2 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 6:adec77323ab2 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 6:adec77323ab2 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 6:adec77323ab2 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 }