Dependencies: mbed C12832 MMA7660 USBDevice
main.cpp
- Committer:
- knasp
- Date:
- 2019-10-24
- Revision:
- 17:0b1c5f6dbb5c
- Parent:
- 16:6b502d21abf4
- Child:
- 18:660b5780aaa3
File content as of revision 17:0b1c5f6dbb5c:
#include "mbed.h" #include "USBKeyboard.h" #include "MMA7660.h" #include "C12832.h" 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); DigitalIn Switch (p8); //switch int main (void) //main program { //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; } 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 (myOrientation == MMA7660::Up){ LCD.printf("LEFT"); Usbkeyboard.printf ("a\0"); 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"); } } /* 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; }