Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed C12832 MMA7660 USBDevice
main.cpp@8:2251d6cc8754, 2019-10-08 (annotated)
- Committer:
- knasp
- Date:
- Tue Oct 08 18:56:36 2019 +0000
- Revision:
- 8:2251d6cc8754
- Parent:
- 7:ffe2220d3880
- Child:
- 9:66681432403a
accelerometer short partially working
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 | 8:2251d6cc8754 | 4 | |
knasp | 8:2251d6cc8754 | 5 | |
knasp | 8:2251d6cc8754 | 6 | |
knasp | 7:ffe2220d3880 | 7 | MMA7660 MMA(p28, p27); |
knasp | 8:2251d6cc8754 | 8 | |
samux | 3:8b56768ceca2 | 9 | USBKeyboard keyboard; |
knasp | 8:2251d6cc8754 | 10 | |
knasp | 7:ffe2220d3880 | 11 | DigitalOut connectionLed(LED1); |
knasp | 7:ffe2220d3880 | 12 | DigitalInOut SCL(p27); |
knasp | 7:ffe2220d3880 | 13 | DigitalInOut SDA(p28); |
knasp | 8:2251d6cc8754 | 14 | |
knasp | 7:ffe2220d3880 | 15 | AnalogIn x(p15),y(p16); |
knasp | 8:2251d6cc8754 | 16 | |
knasp | 8:2251d6cc8754 | 17 | DigitalOut Zaxis_p (USBKeyboard); |
knasp | 8:2251d6cc8754 | 18 | DigitalOut Zaxis_n (USBKeyboard); |
knasp | 8:2251d6cc8754 | 19 | DigitalOut Yaxis_p (USBKeyboard); |
knasp | 8:2251d6cc8754 | 20 | DigitalOut Yaxis_n (USBKeyboard); |
knasp | 8:2251d6cc8754 | 21 | DigitalOut Xaxis_p (USBKeyboard); |
knasp | 8:2251d6cc8754 | 22 | DigitalOut Xaxis_n (USBKeyboard); |
knasp | 8:2251d6cc8754 | 23 | |
knasp | 7:ffe2220d3880 | 24 | //MMA7660::MMA7660(PinName sda, PinName scl, bool active) : _i2c(sda, scl) |
knasp | 8:2251d6cc8754 | 25 | |
knasp | 7:ffe2220d3880 | 26 | int main() |
knasp | 7:ffe2220d3880 | 27 | { |
knasp | 8:2251d6cc8754 | 28 | if (MMA.testConnection()) |
knasp | 8:2251d6cc8754 | 29 | connectionLed = 1; |
knasp | 8:2251d6cc8754 | 30 | |
knasp | 8:2251d6cc8754 | 31 | float X1,Y1; //Z1; //variables to store acceleration values in X and Y |
knasp | 7:ffe2220d3880 | 32 | |
knasp | 7:ffe2220d3880 | 33 | while(1) |
knasp | 7:ffe2220d3880 | 34 | { |
knasp | 7:ffe2220d3880 | 35 | X1=x.read(); //read acceleration values in x direction |
knasp | 7:ffe2220d3880 | 36 | Y1=y.read(); //read acceleration values in y direction |
knasp | 7:ffe2220d3880 | 37 | // Z1=z.read(); |
knasp | 7:ffe2220d3880 | 38 | |
knasp | 8:2251d6cc8754 | 39 | if(X1>0.4) // comparison with threshold values for positive X |
knasp | 8:2251d6cc8754 | 40 | keyboard.printf("a"); // send a specified token(command) |
knasp | 8:2251d6cc8754 | 41 | else if(X1<0.6) // comparison with threshold values for negative X |
knasp | 8:2251d6cc8754 | 42 | keyboard.printf("d"); |
knasp | 8:2251d6cc8754 | 43 | else if(Y1>0.4) // comparison with threshold values for negative Y |
knasp | 8:2251d6cc8754 | 44 | keyboard.printf("s"); |
knasp | 8:2251d6cc8754 | 45 | else if(Y1<0.6) // comparison with threshold values for positive Y |
knasp | 8:2251d6cc8754 | 46 | keyboard.printf("w"); |
knasp | 8:2251d6cc8754 | 47 | // if(Z1>0.55) |
knasp | 7:ffe2220d3880 | 48 | //keyboard.printf("esc\0"); |
knasp | 8:2251d6cc8754 | 49 | //else if(Z1<0.47) |
knasp | 7:ffe2220d3880 | 50 | //keyboard.printf("enter\0"); |
knasp | 8:2251d6cc8754 | 51 | wait(0.01); |
samux | 1:291a88a2c151 | 52 | } |
knasp | 7:ffe2220d3880 | 53 | |
samux | 4:f0df6aae7147 | 54 | } |