
2 buttons and 2 switches, compiles, not tested
Dependencies: mbed C12832 MMA7660 USBDevice
main.cpp@7:ffe2220d3880, 2019-10-05 (annotated)
- Committer:
- knasp
- Date:
- Sat Oct 05 14:53:32 2019 +0000
- Revision:
- 7:ffe2220d3880
- Parent:
- 5:03a4211d593a
- Child:
- 8:2251d6cc8754
plik assignmentu
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux | 1:291a88a2c151 | 1 | #include "mbed.h" |
samux | 1:291a88a2c151 | 2 | #include "USBKeyboard.h" |
knasp | 7:ffe2220d3880 | 3 | #include "MMA7660.h" |
knasp | 7:ffe2220d3880 | 4 | |
knasp | 7:ffe2220d3880 | 5 | |
knasp | 7:ffe2220d3880 | 6 | |
knasp | 7:ffe2220d3880 | 7 | MMA7660 MMA(p28, p27); |
knasp | 7:ffe2220d3880 | 8 | |
samux | 3:8b56768ceca2 | 9 | USBKeyboard keyboard; |
knasp | 7:ffe2220d3880 | 10 | |
knasp | 7:ffe2220d3880 | 11 | DigitalOut connectionLed(LED1); |
knasp | 7:ffe2220d3880 | 12 | DigitalInOut SCL(p27); |
knasp | 7:ffe2220d3880 | 13 | DigitalInOut SDA(p28); |
knasp | 7:ffe2220d3880 | 14 | |
knasp | 7:ffe2220d3880 | 15 | AnalogIn x(p15),y(p16); |
knasp | 7:ffe2220d3880 | 16 | |
knasp | 7:ffe2220d3880 | 17 | AnalogOut Zaxis_p (USBKeyboard); |
knasp | 7:ffe2220d3880 | 18 | AnalogOut Zaxis_n (USBKeyboard); |
knasp | 7:ffe2220d3880 | 19 | AnalogOut Yaxis_p (USBKeyboard); |
knasp | 7:ffe2220d3880 | 20 | AnalogOut Yaxis_n (USBKeyboard); |
knasp | 7:ffe2220d3880 | 21 | AnalogOut Xaxis_p (USBKeyboard); |
knasp | 7:ffe2220d3880 | 22 | AnalogOut Xaxis_n (USBKeyboard); |
knasp | 7:ffe2220d3880 | 23 | |
knasp | 7:ffe2220d3880 | 24 | //MMA7660::MMA7660(PinName sda, PinName scl, bool active) : _i2c(sda, scl) |
knasp | 7:ffe2220d3880 | 25 | |
knasp | 7:ffe2220d3880 | 26 | int main() |
knasp | 7:ffe2220d3880 | 27 | { |
knasp | 7:ffe2220d3880 | 28 | float X1,Y1,Z1; //variables to store acceleration values in X and Y |
knasp | 7:ffe2220d3880 | 29 | |
knasp | 7:ffe2220d3880 | 30 | while(1) |
knasp | 7:ffe2220d3880 | 31 | { |
knasp | 7:ffe2220d3880 | 32 | X1=x.read(); //read acceleration values in x direction |
knasp | 7:ffe2220d3880 | 33 | Y1=y.read(); //read acceleration values in y direction |
knasp | 7:ffe2220d3880 | 34 | // Z1=z.read(); |
knasp | 7:ffe2220d3880 | 35 | |
knasp | 7:ffe2220d3880 | 36 | if(X1>0.55) // comparison with threshold values for positive X |
knasp | 7:ffe2220d3880 | 37 | keyboard.printf("a\0"); // send a specified token(command) |
knasp | 7:ffe2220d3880 | 38 | else if(X1<0.47) // comparison with threshold values for negative X |
knasp | 7:ffe2220d3880 | 39 | keyboard.printf("d\0"); |
knasp | 7:ffe2220d3880 | 40 | if(Y1>0.55) // comparison with threshold values for negative Y |
knasp | 7:ffe2220d3880 | 41 | keyboard.printf("s\0"); |
knasp | 7:ffe2220d3880 | 42 | else if(Y1<0.47) // comparison with threshold values for positive Y |
knasp | 7:ffe2220d3880 | 43 | keyboard.printf("w\0"); |
knasp | 7:ffe2220d3880 | 44 | //if(Z1>0.55) |
knasp | 7:ffe2220d3880 | 45 | //keyboard.printf("esc\0"); |
knasp | 7:ffe2220d3880 | 46 | // else if(Z1<0.47) |
knasp | 7:ffe2220d3880 | 47 | //keyboard.printf("enter\0"); |
knasp | 7:ffe2220d3880 | 48 | wait(0.1); |
samux | 1:291a88a2c151 | 49 | } |
knasp | 7:ffe2220d3880 | 50 | |
samux | 4:f0df6aae7147 | 51 | } |