accelerometer trial
Dependencies: mbed C12832 MMA7660 USBDevice
Diff: main.cpp
- Revision:
- 18:660b5780aaa3
- Parent:
- 17:0b1c5f6dbb5c
- Child:
- 19:18dd700ceae0
- Child:
- 22:a255721ffc58
diff -r 0b1c5f6dbb5c -r 660b5780aaa3 main.cpp --- a/main.cpp Thu Oct 24 19:53:47 2019 +0000 +++ b/main.cpp Sat Oct 26 17:23:19 2019 +0000 @@ -11,29 +11,44 @@ DigitalOut led3(p14); DigitalOut led4(p15); -DigitalIn Switch (p8); //switch - - +DigitalIn Switch1 (p8); //switch mode 1 (arrows) and 2 (letters) +DigitalIn Switch2 (p16); //switch to numbers +DigitalIn Switch3 (p17); //enter +DigitalIn Switch4 (p18); //spacebar int main (void) //main program { - //enum Orientation {Up, Down,Right, Left,Back, Front,Unknown}; + //enum Orientation {Up, Down,Right, Left,Back, Front,Unknown}; MMA7660::Orientation myOrientation; //defining orientation while (true) { - myOrientation = Accelerometer.getOrientation (); - - if (Switch){ - - if (myOrientation == MMA7660::Up){ - LCD.printf("Left"); - Usbkeyboard.keyCode (LEFT_ARROW); - led2=0; - led1=0; - led3=0; - led4=1; + myOrientation = Accelerometer.getOrientation (); //getting the orientation from accelerometer + + + if (Switch4){ + + Usbkeyboard.printf (" "); //spacebar + + } + + if (Switch3){ + + Usbkeyboard.keyCode (RIGHT_ARROW); //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){ @@ -71,12 +86,12 @@ } } - else { + else { //if the switch is off than if (myOrientation == MMA7660::Up){ LCD.printf("LEFT"); - Usbkeyboard.printf ("a\0"); + Usbkeyboard.printf ("a\0"); //instead of simulating pressing of the "left arrow", simulates pressing "a key" led2=0; led1=0; led3=0; @@ -120,52 +135,7 @@ } -/* - float Acc_X = 0; - float Acc_Y = 0; - float Acc_Z = 0; - while (true) { - - Acc_X = Accelerometer.x (); - Acc_Y = Accelerometer.y (); - Acc_Z = Accelerometer.z (); - - LCD.cls (); //LCD display showing the coordinates (turn off when submitting the program as only per programing - LCD.locate (0,0); - LCD.printf("X Axis: %f",Acc_X); - LCD.locate (0,10); - LCD.printf("Y Axis: %f",Acc_Y); - LCD.locate (0,20); - LCD.printf("Z Axis: %f",Acc_Z); - - wait (0.00000000001); - - if (led=1); - - if (Acc_Y>0.08) { //Y axis program - // Usbkeyboard.printf("w\0"); - Usbkeyboard.keyCode (UP_ARROW); - } else if (Acc_Y<0.08) { - // Usbkeyboard.printf("s\0"); - Usbkeyboard.keyCode (DOWN_ARROW); - } - if (Acc_X>0.08) { //X axis program - //Usbkeyboard.printf("w\0"); - Usbkeyboard.keyCode (LEFT_ARROW); - } else if (Acc_X<0.0) { - //Usbkeyboard.printf("s\0"); - Usbkeyboard.keyCode (RIGHT_ARROW); - } - /* - if (Acc_Z>1.5) { //Z axis program - work in progress - Usbkeyboard.printf("w\0"); - //Usbkeyboard.keyCode (LEFT_ARROW); - } elses if (Acc_Z<1.5) { - Usbskeyboard.printf("s\0"); - //Ussbkeyboard.keyCode (RIGHT_ARROW); - } - */ } return false; }