idd hw3

Dependencies:   mbed DebounceIn USBDevice PinDetect

Revision:
2:4b2e3ca87deb
Parent:
1:85b6b5d1528e
Child:
4:c90291fd6cc9
diff -r 85b6b5d1528e -r 4b2e3ca87deb main.cpp
--- a/main.cpp	Fri Sep 26 17:05:33 2014 +0000
+++ b/main.cpp	Fri Sep 26 19:21:07 2014 +0000
@@ -5,7 +5,7 @@
 //LED1: NUM_LOCK
 //LED2: CAPS_LOCK
 //LED3: SCROLL_LOCK
-BusOut leds(LED3);
+BusOut leds(LED1, LED2, LED3);
 DebounceIn accelerate(D7);
 DigitalIn powerUp(D13);
 DigitalIn breakz(D6);
@@ -17,7 +17,7 @@
 AnalogIn accelX(A2);
  
 //USBMouseKeyboard
-USBMouseKeyboard key_mouse;
+USBMouseKeyboard controller;
 
 //Y: 0.43 - 0.56
 //X: 0.39 - 0.57
@@ -25,34 +25,45 @@
 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 (!accelerate) {
+            controller.keyCode('x');
+            if (accelY.read() <= CENTER_LEFT) {
+                //controller.move(-1, 0);
+                controller.keyCode(LEFT_ARROW);
+                controller.keyCode('x');
+            }
+            if (accelY.read() >= CENTER_RIGHT) {
+                //controller.move(1, 0);
+                controller.keyCode(RIGHT_ARROW);
+                controller.keyCode('x');
+            }
+        }
+        if (!powerUp) {
+            controller.keyCode('x');
+            controller.keyCode('s');
+            controller.keyCode('x');
+        }
+        if (!breakz) {
+            controller.keyCode('z');
+        }
+        // Navigation in Game Menu 
         if (accelY.read() <= CENTER_LEFT) {
-            //key_mouse.move(-1, 0);
-            key_mouse.keyCode(LEFT_ARROW);
+            controller.keyCode(LEFT_ARROW);
         }
         if (accelY.read() >= CENTER_RIGHT) {
-            //key_mouse.move(1, 0);
-            key_mouse.keyCode(RIGHT_ARROW);
+            controller.keyCode(RIGHT_ARROW);
         }
         if (accelX.read() <= CENTER_UP) {
-            key_mouse.keyCode(UP_ARROW);
+            controller.keyCode(UP_ARROW);
+            wait(0.1);
         }
         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');
+            controller.keyCode(DOWN_ARROW);
+            wait(0.1);
         }
     }
 }
\ No newline at end of file