chetan chowdary
/
subway_surfsfinal
Getting the real feel of subway Surfs.
main.cpp@0:6f645104ab31, 2017-03-22 (annotated)
- Committer:
- chetan133
- Date:
- Wed Mar 22 16:32:17 2017 +0000
- Revision:
- 0:6f645104ab31
Real Time Subway Surfs.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chetan133 | 0:6f645104ab31 | 1 | #include "mbed.h" |
chetan133 | 0:6f645104ab31 | 2 | #include "USBKeyboard.h" //making virtual ketboard |
chetan133 | 0:6f645104ab31 | 3 | #include "USBSerial.h" //Virtual serial port over USB |
chetan133 | 0:6f645104ab31 | 4 | |
chetan133 | 0:6f645104ab31 | 5 | AnalogIn inputx(p20); // input pins 20,19,18 for x,y,z axis of ADXL335 respectively. |
chetan133 | 0:6f645104ab31 | 6 | AnalogIn inputy(p19); |
chetan133 | 0:6f645104ab31 | 7 | AnalogIn inputz(p18); |
chetan133 | 0:6f645104ab31 | 8 | Serial pc(USBTX,USBRX); //Serial class for transmission of serial data |
chetan133 | 0:6f645104ab31 | 9 | |
chetan133 | 0:6f645104ab31 | 10 | USBKeyboard keyboard; // setting variable |
chetan133 | 0:6f645104ab31 | 11 | DigitalOut myled1(LED1); |
chetan133 | 0:6f645104ab31 | 12 | |
chetan133 | 0:6f645104ab31 | 13 | int main() { |
chetan133 | 0:6f645104ab31 | 14 | |
chetan133 | 0:6f645104ab31 | 15 | int x=0,y=0,z=0,a=0,b=0; // variables for x,y,z axes |
chetan133 | 0:6f645104ab31 | 16 | |
chetan133 | 0:6f645104ab31 | 17 | while(1) |
chetan133 | 0:6f645104ab31 | 18 | {pc.baud(9600); //serial communication rate between pc and mbed. |
chetan133 | 0:6f645104ab31 | 19 | |
chetan133 | 0:6f645104ab31 | 20 | x=inputx*100+1; |
chetan133 | 0:6f645104ab31 | 21 | y=inputy*100-2; |
chetan133 | 0:6f645104ab31 | 22 | z=inputz*100; |
chetan133 | 0:6f645104ab31 | 23 | myled1=!myled1; |
chetan133 | 0:6f645104ab31 | 24 | |
chetan133 | 0:6f645104ab31 | 25 | pc.printf("%d,%d,%d * ",x,y,z); |
chetan133 | 0:6f645104ab31 | 26 | |
chetan133 | 0:6f645104ab31 | 27 | if(y<=52&&y>=48) |
chetan133 | 0:6f645104ab31 | 28 | { |
chetan133 | 0:6f645104ab31 | 29 | a=0; |
chetan133 | 0:6f645104ab31 | 30 | } |
chetan133 | 0:6f645104ab31 | 31 | |
chetan133 | 0:6f645104ab31 | 32 | if(y>54&&a==0) |
chetan133 | 0:6f645104ab31 | 33 | { |
chetan133 | 0:6f645104ab31 | 34 | keyboard.keyCode(RIGHT_ARROW); |
chetan133 | 0:6f645104ab31 | 35 | a=1; |
chetan133 | 0:6f645104ab31 | 36 | } |
chetan133 | 0:6f645104ab31 | 37 | |
chetan133 | 0:6f645104ab31 | 38 | if(y<46&&a==0) |
chetan133 | 0:6f645104ab31 | 39 | { |
chetan133 | 0:6f645104ab31 | 40 | keyboard.keyCode(LEFT_ARROW); |
chetan133 | 0:6f645104ab31 | 41 | a=1; |
chetan133 | 0:6f645104ab31 | 42 | } |
chetan133 | 0:6f645104ab31 | 43 | |
chetan133 | 0:6f645104ab31 | 44 | if(x>=48&&x<=52) |
chetan133 | 0:6f645104ab31 | 45 | { |
chetan133 | 0:6f645104ab31 | 46 | b=0; |
chetan133 | 0:6f645104ab31 | 47 | } |
chetan133 | 0:6f645104ab31 | 48 | |
chetan133 | 0:6f645104ab31 | 49 | if(x<46&&b==0) |
chetan133 | 0:6f645104ab31 | 50 | { |
chetan133 | 0:6f645104ab31 | 51 | keyboard.keyCode(DOWN_ARROW); |
chetan133 | 0:6f645104ab31 | 52 | b=1; |
chetan133 | 0:6f645104ab31 | 53 | } |
chetan133 | 0:6f645104ab31 | 54 | |
chetan133 | 0:6f645104ab31 | 55 | if(x>54&&b==0) |
chetan133 | 0:6f645104ab31 | 56 | { |
chetan133 | 0:6f645104ab31 | 57 | keyboard.keyCode(UP_ARROW); |
chetan133 | 0:6f645104ab31 | 58 | b=1; |
chetan133 | 0:6f645104ab31 | 59 | } |
chetan133 | 0:6f645104ab31 | 60 | |
chetan133 | 0:6f645104ab31 | 61 | } |
chetan133 | 0:6f645104ab31 | 62 | |
chetan133 | 0:6f645104ab31 | 63 | } |