2 buttons and 2 switches, compiles, not tested

Dependencies:   mbed C12832 MMA7660 USBDevice

Committer:
knasp
Date:
Tue Oct 08 20:09:43 2019 +0000
Revision:
9:66681432403a
Parent:
8:2251d6cc8754
Child:
10:150f8d03f18d
simple accelerometer program

Who changed what in which revision?

UserRevisionLine numberNew 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 9:66681432403a 4
knasp 9:66681432403a 5
knasp 9:66681432403a 6
knasp 7:ffe2220d3880 7 MMA7660 MMA(p28, p27);
knasp 9:66681432403a 8
samux 3:8b56768ceca2 9 USBKeyboard keyboard;
knasp 9:66681432403a 10
knasp 7:ffe2220d3880 11 DigitalOut connectionLed(LED1);
knasp 7:ffe2220d3880 12 DigitalInOut SCL(p27);
knasp 7:ffe2220d3880 13 DigitalInOut SDA(p28);
knasp 9:66681432403a 14
knasp 7:ffe2220d3880 15 AnalogIn x(p15),y(p16);
knasp 9:66681432403a 16
knasp 9:66681432403a 17 AnalogOut Zaxis_p (USBKeyboard);
knasp 9:66681432403a 18 AnalogOut Zaxis_n (USBKeyboard);
knasp 9:66681432403a 19 AnalogOut Yaxis_p (USBKeyboard);
knasp 9:66681432403a 20 AnalogOut Yaxis_n (USBKeyboard);
knasp 9:66681432403a 21 AnalogOut Xaxis_p (USBKeyboard);
knasp 9:66681432403a 22 AnalogOut Xaxis_n (USBKeyboard);
knasp 9:66681432403a 23
knasp 9:66681432403a 24
knasp 9:66681432403a 25
knasp 7:ffe2220d3880 26 int main()
knasp 7:ffe2220d3880 27 {
knasp 9:66681432403a 28 float X1,Y1,Z1; //variables to store acceleration values in X and Y
knasp 9:66681432403a 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 9:66681432403a 34 //Z1=z.read();
knasp 7:ffe2220d3880 35
knasp 9:66681432403a 36 if(X1>0.55) // comparison with threshold values for positive X
knasp 9:66681432403a 37 keyboard.printf("a\0"); // send a specified token(command)
knasp 9:66681432403a 38 else if(X1<0.47) // comparison with threshold values for negative X
knasp 9:66681432403a 39 keyboard.printf("d\0");
knasp 9:66681432403a 40 if(Y1>0.55) // comparison with threshold values for negative Y
knasp 9:66681432403a 41 keyboard.printf("s\0");
knasp 9:66681432403a 42 else if(Y1<0.47) // comparison with threshold values for positive Y
knasp 9:66681432403a 43 keyboard.printf("w\0");
knasp 9:66681432403a 44 // if(Z1>0.55)
knasp 9:66681432403a 45 // keyboard.printf("esc\0");
knasp 9:66681432403a 46 // else if(Z1<0.47)
knasp 9:66681432403a 47 // keyboard.printf("enter\0");
knasp 9:66681432403a 48 wait(0.1);
samux 1:291a88a2c151 49 }
knasp 7:ffe2220d3880 50
samux 4:f0df6aae7147 51 }