Dependencies: mbed C12832 MMA7660 USBDevice
Diff: main.cpp
- Revision:
- 9:66681432403a
- Parent:
- 8:2251d6cc8754
- Child:
- 10:150f8d03f18d
diff -r 2251d6cc8754 -r 66681432403a main.cpp --- a/main.cpp Tue Oct 08 18:56:36 2019 +0000 +++ b/main.cpp Tue Oct 08 20:09:43 2019 +0000 @@ -1,54 +1,51 @@ #include "mbed.h" #include "USBKeyboard.h" #include "MMA7660.h" - - - + + + MMA7660 MMA(p28, p27); - + USBKeyboard keyboard; - + DigitalOut connectionLed(LED1); DigitalInOut SCL(p27); DigitalInOut SDA(p28); - + AnalogIn x(p15),y(p16); - -DigitalOut Zaxis_p (USBKeyboard); -DigitalOut Zaxis_n (USBKeyboard); -DigitalOut Yaxis_p (USBKeyboard); -DigitalOut Yaxis_n (USBKeyboard); -DigitalOut Xaxis_p (USBKeyboard); -DigitalOut Xaxis_n (USBKeyboard); - -//MMA7660::MMA7660(PinName sda, PinName scl, bool active) : _i2c(sda, scl) - + +AnalogOut Zaxis_p (USBKeyboard); +AnalogOut Zaxis_n (USBKeyboard); +AnalogOut Yaxis_p (USBKeyboard); +AnalogOut Yaxis_n (USBKeyboard); +AnalogOut Xaxis_p (USBKeyboard); +AnalogOut Xaxis_n (USBKeyboard); + + + int main() { - if (MMA.testConnection()) - connectionLed = 1; - -float X1,Y1; //Z1; //variables to store acceleration values in X and Y - +float X1,Y1,Z1; //variables to store acceleration values in X and Y + while(1) { X1=x.read(); //read acceleration values in x direction Y1=y.read(); //read acceleration values in y direction - // Z1=z.read(); + //Z1=z.read(); - if(X1>0.4) // comparison with threshold values for positive X - keyboard.printf("a"); // send a specified token(command) - else if(X1<0.6) // comparison with threshold values for negative X - keyboard.printf("d"); - else if(Y1>0.4) // comparison with threshold values for negative Y - keyboard.printf("s"); - else if(Y1<0.6) // comparison with threshold values for positive Y - keyboard.printf("w"); - // if(Z1>0.55) - //keyboard.printf("esc\0"); - //else if(Z1<0.47) - //keyboard.printf("enter\0"); - wait(0.01); + if(X1>0.55) // comparison with threshold values for positive X + keyboard.printf("a\0"); // send a specified token(command) + else if(X1<0.47) // comparison with threshold values for negative X + keyboard.printf("d\0"); + if(Y1>0.55) // comparison with threshold values for negative Y + keyboard.printf("s\0"); + else if(Y1<0.47) // comparison with threshold values for positive Y + keyboard.printf("w\0"); + // if(Z1>0.55) + // keyboard.printf("esc\0"); + // else if(Z1<0.47) + // keyboard.printf("enter\0"); + wait(0.1); } } \ No newline at end of file