HW3- swrd

Dependencies:   PinDetect_KL25Z USBDevice mbed

Fork of octasword by TONY WU

Revision:
3:0251fef04954
Parent:
2:082bca930f40
Child:
4:3a66333d6cf0
--- a/main.cpp	Wed Sep 16 22:38:22 2015 +0000
+++ b/main.cpp	Sun Sep 20 22:21:33 2015 +0000
@@ -2,21 +2,21 @@
 #include "PinDetect.h"
 #include "USBKeyboard.h"
 
-Serial pc(USBTX, USBRX);
+//Serial pc(USBTX, USBRX);
 
 AnalogIn x_in(A0);
 AnalogIn y_in(A1);
 AnalogIn z_in(A2);
 
-//USBKeyboard keyboard;
+USBKeyboard keyboard;
 PinDetect start_button(D6);
 PinDetect up_button(D5);
 PinDetect down_button(D4);
 PinDetect right_button(D8);
 PinDetect left_button(D7);
+PinDetect a_button(D9);
 
 int main() {
-    pc.printf("%s", "Welcome to octa sword");
     start_button.mode(PullUp);
     up_button.mode(PullUp);
     down_button.mode(PullUp);
@@ -24,21 +24,21 @@
     left_button.mode(PullUp);
     
     while(1) {
-        if (start_button == 0) {
+        
+        if (x_in.read() > .8 || y_in.read() > .8 || z_in.read() > .8) {
+            keyboard.printf("%s", "a");
+        } else if (start_button == 0) {
             keyboard.keyCode(32);
         } else if (up_button == 0) {
-            keyboard.keyCode(32);
+            keyboard.keyCode(UP_ARROW);
         } else if (down_button == 0) {
-            keyboard.keyCode(32);
+            keyboard.keyCode(DOWN_ARROW);
         } else if (right_button == 0) {
-            keyboard.keyCode(32);
+            keyboard.keyCode(RIGHT_ARROW);
         } else if (left_button == 0) {
-            keyboard.keyCode(32);
-        }   
-        
-        pc.printf("x is: %f\n\r", x_in.read());
-        pc.printf("y is: %f\n\r", y_in.read());
-        pc.printf("z is: %f\n\r", y_in.read());
-        wait(.1);
+            keyboard.keyCode(LEFT_ARROW);
+        } else if (a_button ==0) {
+            keyboard.printf("%s", "a");
+        }
     }
 }