Accelerator test for force measurement all axis. v1

Dependencies:   MMA8451Q SLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
scohennm
Date:
Mon Dec 01 00:29:40 2014 +0000
Parent:
1:6c2ec7b0e1c9
Commit message:
Added all acc vectors

Changed in this revision

TSI.lib Show diff for this revision Revisions of this file
lcd_acc_46_v3.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 6c2ec7b0e1c9 -r 8cdbe8a96b59 TSI.lib
--- a/TSI.lib	Sun Nov 30 01:04:47 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/TSI/#1a60ef257879
diff -r 6c2ec7b0e1c9 -r 8cdbe8a96b59 lcd_acc_46_v3.cpp
--- a/lcd_acc_46_v3.cpp	Sun Nov 30 01:04:47 2014 +0000
+++ b/lcd_acc_46_v3.cpp	Mon Dec 01 00:29:40 2014 +0000
@@ -18,9 +18,17 @@
 #define SCALING 13
 #define RSTARTMESS "RSET"
 #define MAXVECT "MAXV"
+#define XCOMP "XCMP"
 #define YCOMP "YCMP"
+#define ZCOMP "ZCMP"
 #define ANALTOVOLTS 3.3
 #define LEDDELAY 0.400
+//define states
+#define NUMSTATES 4
+#define XCOMPD 0
+#define YCOMPD 1
+#define ZCOMPD 2
+#define VMAXD 3
 
 #define PROGNAME "LCD_ACC_LCDv3 46\r/n"
 
@@ -59,14 +67,8 @@
         slcd.clear();
         slcd.printf(lMess);
 } 
-void GetOffsets(float *xo, float *yo){
-    LCDMess(RSTARTMESS, BLINKTIME);
-    *xo = acc.getAccX();
-    *yo = acc.getAccY();
-    return;
-}
 
-  
+
 void allLEDsOFF(int numberOfLEDS) {
     int i;
     for (i=0;i<numberOfLEDS; i++){
@@ -92,12 +94,10 @@
     int LButtonState;
     DigitalIn RtButton(PTC12);
     DigitalIn LftButton(PTC3);
-    float xOffset;
-    float yOffset;
-    int displayState = true; 
+    int displayState = XCOMPD; 
     float xAcc = 0.0;
     float yAcc = 0.0;
-//    float zAcc;
+    float zAcc = 0.0;
     float vector;
     float vMax = 0.0;
     float DisplayTime = DATADISPDWELL;
@@ -108,10 +108,9 @@
 #ifdef PRINTDBUG
         pc.printf(PROGNAME);
 #endif
+    LCDMess(RSTARTMESS, BLINKTIME);
 // Initialze readings and sequence the LED's for dramtic effect.
     allLEDsOFF(NUMLEDS);
-    GetOffsets(&xOffset, &yOffset); 
-//    runLEDs(NUMLEDS);
     blinkTimer.start();
     blinkTimer.reset();
     displayTimer.start();
@@ -121,32 +120,35 @@
     
 // main loop forever 
     while(true) {
-// Alive LEDs
-        while(blinkTimer.read()> LEDDELAY) {     
-            LEDs[0].write(outState);
-            LEDs[1].write(!outState);
-            outState = !outState; 
-            blinkTimer.reset();
-        }
+
 // Handle user input for display selections
         RButtonState = !RtButton; // button is pulled up so false is when button is pushed it's inverted to avoid confusion downstream
         if (RButtonState){
             vMax = 0.0; // Clear vMax
-            GetOffsets(&xOffset, &yOffset); // set zero baseling for position 
-#ifdef PRINTDBUG
-            pc.printf("xOffset = %f\r\n", xOffset);
-            pc.printf("yOffset = %f\r\n", yOffset);
-#endif           
+            LCDMess(RSTARTMESS, BLINKTIME);
         }
         LButtonState = !LftButton;
         if (LButtonState) {  //Change data that is displayed
-            displayState = !displayState;
+            displayState = (displayState + 1) % NUMSTATES;
             // Change to switch/case soon.
-            if (displayState) {
-                LCDMess(YCOMP,BLINKTIME);
-            }else {
-                LCDMess(MAXVECT,BLINKTIME);
-            }
+            switch (displayState){
+                case XCOMPD: {
+                    LCDMess(XCOMP,BLINKTIME);
+                    break;
+                }
+                case YCOMPD: {
+                    LCDMess(YCOMP,BLINKTIME);
+                    break;
+                }
+                case ZCOMPD: {
+                    LCDMess(ZCOMP,BLINKTIME);
+                    break;
+                }
+                case VMAXD:{
+                    LCDMess(MAXVECT,BLINKTIME);
+                    break;
+                }
+            }// switch        
         }
         
 // --------------------------------------------
@@ -155,30 +157,49 @@
 // No offset
             xAcc = abs(acc.getAccX());
             yAcc = abs(acc.getAccY());
-//          zAcc = abs(acc.getAccZ());
+            zAcc = abs(acc.getAccZ());
  // Calulate vector sum of x,y and z reading.       
-            vector = sqrt(pow(xAcc,2) + pow(yAcc,2));
+            vector = sqrt(pow(xAcc,2) + pow(zAcc,2));
             if (vector > vMax) {
                 vMax = vector;
             }
             dataTimer.reset();
         }
 #ifdef PRINTDBUG
-        pc.printf("vector = %f\r\n",  yAcc);
+        pc.printf("vector = %f\r\n",  xAcc);
         pc.printf("scaling = %f\r\n", scaleExpansion);
         pc.printf("RawTemp = %f\r\n", FDeg);
 #endif
 // Display the appropriate data on the LCD based upon what mode was chosen
         while (displayTimer.read() > DisplayTime){
-            if (displayState) {
-                sprintf (lcdData,"%4.3f",yAcc);
-            }else {
-                sprintf (lcdData,"%4.3f",vMax);
+            switch (displayState) {
+                case XCOMPD: {
+                    sprintf (lcdData,"%4.3f",xAcc);
+                    break;
+                }
+                case YCOMPD: {
+                    sprintf (lcdData,"%4.3f",yAcc);
+                    break;
+                }
+                case ZCOMPD: {
+                    sprintf (lcdData,"%4.3f",zAcc);
+                    break;
+                }
+                case VMAXD:{
+                    sprintf (lcdData,"%4.3f",vMax);
+                    break;
+                }
             }
- //         LCDMess(lcdData,DisplayTime);
             LCDMessNoDwell(lcdData);
             displayTimer.reset();
         } // displaytimer 
-// Wait then do the whole thing again.   
+// Wait then do the whole thing again.  
+// Alive LEDs
+        while(blinkTimer.read()> LEDDELAY) {     
+            LEDs[0].write(outState);
+            LEDs[1].write(!outState);
+            outState = !outState; 
+            blinkTimer.reset();
+        } 
     }//forever loop
 }// main
\ No newline at end of file