Getting the real feel of subway Surfs.

Dependencies:   USBDevice mbed

Revision:
0:6f645104ab31
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Mar 22 16:32:17 2017 +0000
@@ -0,0 +1,63 @@
+#include "mbed.h"
+#include "USBKeyboard.h" //making virtual ketboard
+#include "USBSerial.h"  //Virtual serial port over USB
+
+ AnalogIn inputx(p20); // input pins 20,19,18 for x,y,z axis of ADXL335 respectively.
+AnalogIn inputy(p19);
+AnalogIn inputz(p18);
+Serial pc(USBTX,USBRX);  //Serial class for transmission of serial data
+
+USBKeyboard keyboard;  // setting variable    
+DigitalOut myled1(LED1);
+ 
+int main() {
+
+  int x=0,y=0,z=0,a=0,b=0; // variables for x,y,z axes
+
+  while(1)
+ {pc.baud(9600);  //serial communication rate between pc and mbed.
+             
+  x=inputx*100+1;
+  y=inputy*100-2;
+  z=inputz*100; 
+  myled1=!myled1; 
+     
+  pc.printf("%d,%d,%d * ",x,y,z);
+           
+  if(y<=52&&y>=48)
+  {
+    a=0;    
+  }
+
+  if(y>54&&a==0)
+  {
+    keyboard.keyCode(RIGHT_ARROW);
+    a=1;
+  }
+
+  if(y<46&&a==0)
+  {
+   keyboard.keyCode(LEFT_ARROW);
+   a=1;
+  }
+  
+  if(x>=48&&x<=52)
+  {
+    b=0;    
+  }
+  
+  if(x<46&&b==0)
+  {
+    keyboard.keyCode(DOWN_ARROW);
+    b=1;
+  }
+       
+  if(x>54&&b==0)
+  {
+   keyboard.keyCode(UP_ARROW);
+    b=1;
+}
+
+ }
+        
+        }
\ No newline at end of file