ALM Final Project

Dependencies:   MMA8451Q SLCD_minus_mod mbed

Fork of ACC_LCD_341_Basic by Stanley Cohen

Files at this revision

API Documentation at this revision

Comitter:
annalou
Date:
Mon Nov 28 01:29:12 2016 +0000
Parent:
5:29c6ba524263
Commit message:
ALM_FINAL

Changed in this revision

acc_341.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/acc_341.cpp	Mon Nov 14 15:50:33 2016 +0000
+++ b/acc_341.cpp	Mon Nov 28 01:29:12 2016 +0000
@@ -9,8 +9,9 @@
  Works pretty well. Still rough, program wise - sc 140710
  */
 
-#define DATAINTERVAL 0.200
+#define DATAINTERVAL 0.150
 #define LCDDATALEN 10
+#define LCDAXISLEN 3
 
 #define PROGNAME "ACCLCD341-541\r\n"
 
@@ -30,6 +31,7 @@
 
 SLCD slcd; //define LCD display
 char lcdData[LCDDATALEN]; //buffer needs places dor decimal pt and colon
+char lcdAxis[LCDAXISLEN];
 
 MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
 Serial pc(USBTX, USBRX);
@@ -41,11 +43,21 @@
         slcd.Home();
         slcd.clear();
         slcd.printf(lMess);
+
 } 
 
-void LCDsignedFloat(float theNumber){
+void LCDsignedFloat(float theNumber, Timer dataTime, char axis){
     sprintf (lcdData," %3.2f",theNumber); 
-    if (theNumber < 0.0) sprintf (lcdData,"<%3.2f",fabs(theNumber));   
+    if ((dataTime < 0.150) && (axis == 'X'))
+    { sprintf (lcdAxis,"%c", axis);
+    if (theNumber < 0.0) sprintf (lcdData,"<%3.2f",fabs(theNumber));}
+    else if ((dataTime < 0.150) && (axis == 'Y')){
+         sprintf (lcdAxis,"%c", axis); 
+         if (theNumber < 0.0) sprintf (lcdData,"<%3.2f",fabs(theNumber));}
+    else {sprintf (lcdAxis,"%c", axis);
+    if (theNumber < 0.0) sprintf (lcdData,"<%3.2f",fabs(theNumber));}; 
+    
+     
     LCDMess(lcdData); 
 } 
 
@@ -63,20 +75,23 @@
     initialize_global_vars();
 // main loop forever 
     while(true) {
-        if(dataTimer.read() > DATAINTERVAL){
-            dataTimer.reset();             
+        if(dataTimer.read() > DATAINTERVAL){            
 //Get accelerometer data - tilt angles minus offset for zero mark.
             xAcc = acc.getAccX();
-            yAcc = acc.getAccY(); 
+             LCDsignedFloat(xAcc, dataTimer, 'X');
+              dataTimer.reset(); 
+            yAcc = acc.getAccY();
+             LCDsignedFloat(yAcc, dataTimer, 'Y'); 
+              dataTimer.reset(); 
             zAcc = acc.getAccZ();     
+             LCDsignedFloat(zAcc, dataTimer, 'Z');
+              dataTimer.reset(); 
  
 #ifdef PRINTDBUG
         pc.printf("xAcc = %f\r\n", xAcc);
         pc.printf("yAcc = %f\r\n", yAcc);
         pc.printf("zAcc = %f\r\n", zAcc);
 #endif
-
-        LCDsignedFloat(xAcc);
 // Wait then do the whole thing again.
        }
     }