Dependencies: mbed C12832 MMA7660 USBDevice
Diff: main.cpp
- Revision:
- 21:53426ae5b7b1
- Parent:
- 10:150f8d03f18d
- Child:
- 22:f7e4b453f684
--- a/main.cpp Thu Oct 10 16:55:08 2019 +0000 +++ b/main.cpp Sun Oct 27 12:19:15 2019 +0000 @@ -3,62 +3,162 @@ #include "MMA7660.h" #include "C12832.h" +#include "stdint.h" +#define REPORT_ID_KEYBOARD 1 +#define REPORT_ID_VOLUME 3 -MMA7660 MMA(p28, p27); - -USBKeyboard keyboard; - -DigitalOut connectionLed(LED1); -DigitalInOut SCL(p27); -DigitalInOut SDA(p28); - +typedef struct { + unsigned char usage; + unsigned char modifier; +} KEYMAP; - -AnalogOut Zaxis_p (USBKeyboard); -AnalogOut Zaxis_n (USBKeyboard); -AnalogOut Yaxis_p (USBKeyboard); -AnalogOut Yaxis_n (USBKeyboard); -AnalogOut Xaxis_p (USBKeyboard); -AnalogOut Xaxis_n (USBKeyboard); - -C12832 LCD (p5,p7,p6,p8,p11); +#ifdef US_KEYBOARD +/* US keyboard (as HID standard) */ +#define KEYMAP_SIZE (152) +const KEYMAP keymap[KEYMAP_SIZE] = { + + {0x28, 0}, /* LF */ /* Keyboard Return (Enter) */ + +}; +#endif -int main() -{ - float X1,Y1,Z1; //variables to store acceleration values in X and Y +MMA7660 Accelerometer (p28,p27); //define accelerometer +USBKeyboard Usbkeyboard; //define keyboard +C12832 LCD (p5,p7,p6,p8,p11); //define LCD + +DigitalOut led1(p12); //leds +DigitalOut led2(p13); +DigitalOut led3(p14); +DigitalOut led4(p15); - while(1) { - X1 = MMA.x (); - Y1 = MMA.y (); - Z1 = MMA.z (); - - LCD.cls (); - LCD.locate (0,0); - LCD.printf("X Axis: %f", X1); - LCD.locate (0,10); - LCD.printf("Y Axis: %f", Y1); - LCD.locate (0,20); - LCD.printf("Z Axis: %f", Z1); +DigitalIn Switch1 (p8); //switch mode 1 (arrows) and 2 (letters) +DigitalIn Switch2 (p16); //switch to numbers +DigitalIn Switch3 (p15); //enter +DigitalIn Switch4 (p14); //spacebar + +int main (void) //main program +{ + //enum Orientation {Up, Down,Right, Left,Back, Front,Unknown}; + MMA7660::Orientation myOrientation; //defining orientation -/* - 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); - */ - - - } + while (true) { + + + myOrientation = Accelerometer.getOrientation (); //getting the orientation from accelerometer + + + if (Switch4){ + + Usbkeyboard.printf (" "); //spacebar + + } + + if (Switch3){ + + Usbkeyboard.keyCode(0x28, 0); //enter will be HERE + + } + + if (Switch1){ //if the switch is on + + if (myOrientation == MMA7660::Up){ //if the orientation is up + + LCD.printf("Left"); //print "left" on LCD (due to orientation of the accelerometer on the limb, the directions are changed) + Usbkeyboard.keyCode (LEFT_ARROW); //device simulates pressing "left arrow key" on the keyboard + led2=0; //led off + led1=0; //led off + led3=0; //led off + led4=1; //led on + } + else if (myOrientation == MMA7660::Down){ + + LCD.printf("Right"); + Usbkeyboard.keyCode (RIGHT_ARROW); + led3=0; + led1=0; + led2=1; + led4=0; + } + else if (myOrientation == MMA7660::Left){ + + LCD.printf("UP"); + Usbkeyboard.keyCode (UP_ARROW); + led1=1; + led3=0; + led2=0; + led4=0; + } + else if (myOrientation == MMA7660::Right){ + + LCD.printf("DOWN"); + Usbkeyboard.keyCode (DOWN_ARROW); + led4=0; + led1=0; + led3=1; + led2=0; + + + } + else if (myOrientation == MMA7660::Unknown){ + + LCD.printf("Don't Know"); + + } + } + + else { //if the switch is off than + + if (myOrientation == MMA7660::Up){ + + LCD.printf("LEFT"); + Usbkeyboard.printf ("a\0"); //instead of simulating pressing of the "left arrow", simulates pressing "a key" + led2=0; + led1=0; + led3=0; + led4=1; + } + else if (myOrientation == MMA7660::Down){ + + LCD.printf("right"); + Usbkeyboard.printf ("d\0"); + led3=0; + led1=0; + led2=1; + led4=0; + } + else if (myOrientation == MMA7660::Left){ + + LCD.printf("Up"); + Usbkeyboard.printf ("w\0"); + led1=1; + led3=0; + led2=0; + led4=0; + } + else if (myOrientation == MMA7660::Right){ + + LCD.printf("Down"); + Usbkeyboard.printf ("s\0"); + led4=0; + led1=0; + led3=1; + led2=0; + + + + } + else if (myOrientation == MMA7660::Unknown){ + + LCD.printf("Don't Know"); + + } + + } + -} \ No newline at end of file + } +return false; +} +