3 axis accel

Dependencies:   MMA8451Q SLCD_minus_mod mbed

Fork of ACC_LCD_341_Basic by Stanley Cohen

Revision:
4:1d559bac561a
Parent:
3:c5291c70af48
Child:
5:29c6ba524263
diff -r c5291c70af48 -r 1d559bac561a acc_341.cpp
--- a/acc_341.cpp	Sat Nov 05 23:46:00 2016 +0000
+++ b/acc_341.cpp	Sun Nov 06 23:56:18 2016 +0000
@@ -10,6 +10,7 @@
  */
 
 #define DATAINTERVAL 0.200
+#define LCDDATALEN 10
 
 #define PROGNAME "ACCLCD341-541\r\n"
 
@@ -28,6 +29,7 @@
 #define MMA8451_I2C_ADDRESS (0x1d<<1)
 
 SLCD slcd; //define LCD display
+char lcdData[LCDDATALEN]; //buffer needs places dor decimal pt and colon
 
 MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
 Serial pc(USBTX, USBRX);
@@ -40,6 +42,13 @@
         slcd.clear();
         slcd.printf(lMess);
 } 
+
+void LCDsignedFloat(float theNumber){
+    sprintf (lcdData,"%3.2f",theNumber); 
+    if (theNumber < 0.0) sprintf (lcdData,">%3.2f",fabs(theNumber));   
+    LCDMess(lcdData); 
+} 
+
 void initialize_global_vars(){
     pc.printf(PROGNAME);
     dataTimer.start();
@@ -49,7 +58,7 @@
 int main() {
     float xAcc;
     float yAcc; 
-    char lcdData[10]; //buffer needs places dor decimal pt and colon
+    float zAcc; 
     
     initialize_global_vars();
 // main loop forever 
@@ -58,16 +67,16 @@
             dataTimer.reset();             
 //Get accelerometer data - tilt angles minus offset for zero mark.
             xAcc = acc.getAccX();
-            yAcc = acc.getAccY();     
+            yAcc = acc.getAccY(); 
+            zAcc = acc.getAccZ();     
  
 #ifdef PRINTDBUG
         pc.printf("xAcc = %f\r\n", xAcc);
         pc.printf("yAcc = %f\r\n", yAcc);
+        pc.printf("zAcc = %f\r\n", zAcc);
 #endif
 
-        sprintf (lcdData,"%3.2f",xAcc); 
-        if (xAcc < 0) sprintf (lcdData,">%3.2f",fabs(xAcc));   
-        LCDMess(lcdData); 
+        LCDsignedFloat(zAcc);
 // Wait then do the whole thing again.
        }
     }