Library for MMA7660FC Accelerometer device

Dependents:   TestCode_MMA7660FC 3D_Accelerometer_Tester RTOS-aap-board-modules embed_Grove_3-Axis_Digital_Accelerometer ... more

Files at this revision

API Documentation at this revision

Comitter:
edodm85
Date:
Wed Jul 04 20:20:27 2012 +0000
Parent:
3:df25c72e16be
Child:
5:d2f90c0be13f
Commit message:
Rev 5

Changed in this revision

MMA7660FC.cpp Show annotated file Show diff for this revision Revisions of this file
MMA7660FC.h Show annotated file Show diff for this revision Revisions of this file
--- a/MMA7660FC.cpp	Tue Jul 03 18:37:19 2012 +0000
+++ b/MMA7660FC.cpp	Wed Jul 04 20:20:27 2012 +0000
@@ -33,6 +33,10 @@
 #define PD_STATUS 0xA           // Tap/Pulse Debounce Count Register (Read/Write)
 
 
+float TILT_XY[64] = {0, 2.69, 5.38, 8.08, 10.81, 13.55, 16.33, 19.16, 22.02, 24.95, 27.95, 31.04, 34.23, 37.54, 41.01, 44.68, 48.59, 52.83, 57.54, 62.95, 69.64, 79.86, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -79.86, -69.64, -62.95, -57.54, -52.83, -48.59, -44.68, -41.01, -37.54, -34.23, -31.04, -27.95, -24.95, -22.02, -19.16, -16.33, -13.55, -10.81, -8.08, -5.38, -2.69}; 
+float TILT_Z[64] = {90.00, 87.31, 84.62, 81.92, 79.19, 76.45, 73.67, 70.84, 67.98, 65.05, 62.05, 58.96, 55.77, 52.46, 48.99, 45.32, 41.41, 37.17, 32.46, 27.05, 20.36, 10.14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -10.14, -20.36, -27.05, -32.46, -37.17, -41.41, -45.32, -48.99, -52.46, -55.77, -58.96, -62.05, -65.05, -67.98, -70.84, -73.67, -76.45, -79.19, -81.92, -84.62};
+
+
 
         // Connect module at I2C address addr using I2C port pins sda and scl
 MMA7660FC::MMA7660FC(PinName sda, PinName scl, int addr) : m_i2c(sda, scl), m_addr(addr)
@@ -59,8 +63,8 @@
 }
 
 
-        // Reads X, Y, Z data
-void MMA7660FC::read_g(int *x, int *y, int *z)
+        // Reads the tilt angle
+void MMA7660FC::read_Tilt(float *x, float *y, float *z)
 {
 
     const char Addr_X = OUT_X;
@@ -69,9 +73,10 @@
     m_i2c.write(m_addr, &Addr_X, 1);         // Pointer to the OUT_X register
     m_i2c.read(m_addr, buf, 3);              // Read register content into buffer with 6bit
     
-    *x = buf[0];
-    *y = buf[1];
-    *z = buf[2];      
+    // returns the x, y, z coordinates transformed into full degrees
+    *x = TILT_XY[buf[0]];
+    *y = TILT_XY[buf[1]];
+    *z = TILT_Z[buf[2]];      
   
 }
 
--- a/MMA7660FC.h	Tue Jul 03 18:37:19 2012 +0000
+++ b/MMA7660FC.h	Wed Jul 04 20:20:27 2012 +0000
@@ -42,10 +42,10 @@
  *      while(1)
  *      {
  *          int x=0, y=0, z=0;
- *          Acc.read_g(&x, &y, &z);
- *          pc.printf("x: \n", x);
- *          pc.printf("x: \n", y);
- *          pc.printf("x: \n", z);
+ *          Acc.read_Tilt(&x, &y, &z);
+ *          pc.printf("Tilt x: %2.2f degree \n", x);                    // Print the tilt orientation of the X axis
+ *          pc.printf("Tilt y: %2.2f degree \n", y);                    // Print the tilt orientation of the Y axis
+ *          pc.printf("Tilt z: %2.2f degree \n", z);                    // Print the tilt orientation of the Z axis
  *          wait(1);       
  *      }
  * }
@@ -74,13 +74,13 @@
         */
       void init();
     
-       /** Read the x,y,z axis acceleration and return a 6bit unsigned data
+       /** Read the Tilt Angle using Three Axis
         *
-        * @param *x Value of X acceleration
-        * @param *y Value of Y acceleration
-        * @param *z Value of Z acceleration
+        * @param *x Value of x tilt
+        * @param *y Value of y tilt
+        * @param *z Value of z tilt
         */
-      void read_g(int *x, int *y, int *z);
+      void read_Tilt(float *x, float *y, float *z);
       
       /** Read the x register of the MMA7660FC
         *
@@ -98,7 +98,7 @@
         *
         * @returns The value of z acceleration
         */
-      float read_z();
+       float read_z();
             
         /** Read from specified MMA7660FC register
          *