Test program for the MMA8451Q library

Dependencies:   FRDM_MMA8451Q mbed

Fork of FRDM_MMA8451Q by mbed official

Files at this revision

API Documentation at this revision

Comitter:
clemente
Date:
Thu Aug 22 15:22:40 2013 +0000
Parent:
8:9914c50f5e9a
Child:
10:1c11c7f28fff
Commit message:
Modified for new raw mode functions.

Changed in this revision

MMA8451Q.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/MMA8451Q.lib	Tue May 28 20:24:11 2013 +0000
+++ b/MMA8451Q.lib	Thu Aug 22 15:22:40 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/clemente/code/FRDM_MMA8451Q/#2aa9b1668d14
+http://mbed.org/users/clemente/code/FRDM_MMA8451Q/#fa532bf396fb
--- a/main.cpp	Tue May 28 20:24:11 2013 +0000
+++ b/main.cpp	Thu Aug 22 15:22:40 2013 +0000
@@ -16,6 +16,7 @@
 
 unsigned int ff, md, od;
 float sensor_data[3];
+int16_t raw_data[3];
 
 int main(void) {
 
@@ -62,6 +63,21 @@
                 pc.printf("Data Ready\r\n");
                 acc.DataReady( &dataready, cODR_1_56HZ);
                 break;
+                case 'w':
+                // Read the accelorometer value in raw mode.
+                pc.printf("Polling method and data raw\r\n");
+                //
+                while( 1) {
+                    if ( pc.readable()) {
+                        break;
+                    }
+                    // Check data availability
+                    if ( acc.getAccRawAllAxis( &raw_data[0])) {
+                        pc.printf("X: %X, Y: %X, Z: %X\r\n", raw_data[0], raw_data[1], raw_data[2]);
+                        wait( 1.0);
+                    }
+                }
+                break;
 
             }
         }
@@ -124,8 +140,9 @@
     pc.printf( "ff %d\r\n", ff);    
 }
 
+// callback function for data reading
 void dataready( void)
 {
     acc.getAccAllAxis( &sensor_data[0]);
-    pc.printf("X %f, Y %f, Z %f\r\n", sensor_data[0], sensor_data[1], sensor_data[2]);
+    pc.printf("X: %f, Y: %f, Z: %f\r\n", sensor_data[0], sensor_data[1], sensor_data[2]);
 }
\ No newline at end of file