Dependencies:   mbed C12832 MMA7660 USBDevice

Revision:
11:73e8c1bb5467
Parent:
10:150f8d03f18d
Child:
12:b6a803a6450e
Child:
14:116f94a428c9
--- a/main.cpp	Thu Oct 10 16:55:08 2019 +0000
+++ b/main.cpp	Thu Oct 10 20:03:05 2019 +0000
@@ -3,62 +3,56 @@
 #include "MMA7660.h"
 #include "C12832.h"
 
-
-
-MMA7660 MMA(p28, p27);
-
-USBKeyboard keyboard;
+MMA7660         Accelerometer (p28,p27);
+USBKeyboard     Usbkeyboard;
+C12832          LCD (p5,p7,p6,p8,p11);
 
-DigitalOut connectionLed(LED1);
-DigitalInOut SCL(p27);
-DigitalInOut SDA(p28);
+int main (void)
+{
 
+    float Acc_X = 0;
+    float Acc_Y = 0;
+    float Acc_Z = 0;
 
+    while (true) {
 
-AnalogOut Zaxis_p (USBKeyboard);
-AnalogOut Zaxis_n (USBKeyboard);
-AnalogOut Yaxis_p (USBKeyboard);
-AnalogOut Yaxis_n (USBKeyboard);
-AnalogOut Xaxis_p (USBKeyboard);
-AnalogOut Xaxis_n (USBKeyboard);
+        Acc_X = Accelerometer.x ();
+        Acc_Y = Accelerometer.y ();
+        Acc_Z = Accelerometer.z ();
 
-C12832      LCD (p5,p7,p6,p8,p11);
-
+        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);
 
-int main()
-{
-    float X1,Y1,Z1;                //variables to store acceleration values in X and Y
+        wait (0.00000000001);
 
-    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);
-        
-/*
-        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);
-  */
-  
-  
+        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);
+        }
+        */
     }
-
-}
\ No newline at end of file
+    return false;
+}