added switch case for g limit

Dependencies:   EMench_MMA8451Q SLCD mbed

Fork of LCD_ACC_46_v4-2g by Stanley Cohen

Files at this revision

API Documentation at this revision

Comitter:
menchacaeli
Date:
Wed Feb 22 03:08:49 2017 +0000
Parent:
4:41920817d234
Commit message:
EMench_SSD645_HW6.1 added a new switch case for the g limit

Changed in this revision

MMA8451Q.lib Show annotated file Show diff for this revision Revisions of this file
lcd_acc_46_v-2g.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 41920817d234 -r cba53136f4b9 MMA8451Q.lib
--- a/MMA8451Q.lib	Fri Feb 10 19:28:50 2017 +0000
+++ b/MMA8451Q.lib	Wed Feb 22 03:08:49 2017 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/emilmont/code/MMA8451Q/#c4d879a39775
+https://developer.mbed.org/users/menchacaeli/code/EMench_MMA8451Q/#522c62237b36
diff -r 41920817d234 -r cba53136f4b9 lcd_acc_46_v-2g.cpp
--- a/lcd_acc_46_v-2g.cpp	Fri Feb 10 19:28:50 2017 +0000
+++ b/lcd_acc_46_v-2g.cpp	Wed Feb 22 03:08:49 2017 +0000
@@ -1,10 +1,26 @@
 #include "mbed.h"
 #include "MMA8451Q.h"
+#include "MMA8451Q8.h"
 #include "SLCD.h"
 /* 
 Test of the accelerometer, digital I/O, on-board LCD screen, and 16-bit ADC.
  
  */
+ // Library MMA8451Q defines
+#define REG_WHO_AM_I   0x0D
+#define REG_CTRL_REG_1 0x2A
+#define REG_OUT_X_MSB  0x01
+#define REG_OUT_Y_MSB  0x03
+#define REG_OUT_Z_MSB  0x05
+#define XYZ_DATA_CFG   0x0E
+
+#define UINT14_MAX 16383
+
+#define MAX_2G 0x00
+#define MAX_4G 0x01
+#define MAX_8G 0x02
+
+#define GSCALING 1024.0
 
 #define BLINKTIME 0.7
 #define DATATIME 0.1
@@ -18,14 +34,17 @@
 #define XCOMP "XCMP"
 #define YCOMP "YCMP"
 #define ZCOMP "ZCMP"
+#define XRAWP "XRAW"
+#define GLIMP "GLIM"
 #define ANALTOVOLTS 3.3
 #define LEDDELAY 0.400
 //define states
-#define NUMSTATES 4
+#define NUMSTATES 5
 #define XCOMPD 0
 #define YCOMPD 1
 #define ZCOMPD 2
 #define VMAXD 3
+#define XRAWD 4
 
 #define PROGNAME "LCD_ACC_LCDv3 46\r/n"
 
@@ -52,6 +71,7 @@
 DigitalOut LEDs[NUMLEDS]={LED_RED, LED_GREEN}; //Indicator LEDs
 Serial pc(USBTX, USBRX);
 
+int16_t xAccBits; // making local creates a warning
 
 void LCDMess(char *lMess, float dWait){
         slcd.Home();
@@ -71,11 +91,8 @@
     for (i=0;i<numberOfLEDS; i++){
             LEDs[i] = LEDOFF;
         }
-
 }
 
-
-
 int main() {
     
     int RButtonState;
@@ -132,21 +149,33 @@
                     LCDMess(ZCOMP,BLINKTIME);
                     break;
                 }
-                case VMAXD:{
+                case VMAXD: {
                     LCDMess(MAXVECT,BLINKTIME);
                     break;
                 }
+                case XRAWD: {
+                    LCDMess(XRAWP,BLINKTIME);
+                    break;
+                }
+                case GLIMD: {
+                    LCDMess(GLIMP,BLINKTIME);
+                    break;
+                }
             }// switch        
         }
         
 // --------------------------------------------
         while (dataTimer.read() > DATATIME){
 // No offset
-            xAcc = abs(acc.getAccX());
-            yAcc = abs(acc.getAccY());
+            xAcc = abs(acc.getAccX());            
+            yAcc = abs(acc.getAccY());            
             zAcc = abs(acc.getAccZ());
+// test getting raw bits
+            xAccBits = acc.getAccAxis(REG_OUT_X_MSB);
+// test g limit
+            gLimit = data[2].setGLimit();
  // Calulate vector sum of x,y and z reading.       
-//            vector = sqrt(pow(xAcc,2) + pow(zAcc,2));
+ //           vector = sqrt(pow(xAcc,2) + pow(zAcc,2));
             vector = zAcc;
             if (vector > vMax) {
                 vMax = vector;
@@ -173,6 +202,14 @@
                     sprintf (lcdData,"%4.3f",vMax);
                     break;
                 }
+                case XRAWD:{
+                    sprintf (lcdData,"%4d",xAccBits);
+                    break;
+                }
+                case GLIMD:{
+                    sprintf (lcdData,"%4d",gLimit);
+                    break;
+                }
             }
             LCDMessNoDwell(lcdData);
             displayTimer.reset();