samux MMA8451Q accelerometer library

Dependents:   AirMouse FRDM_LCD4884 TextLCD_HelloWorld FRDM_MMA8451Q ... more

Files at this revision

API Documentation at this revision

Comitter:
chris
Date:
Fri Oct 12 11:30:34 2012 +0000
Parent:
2:a077541cbadc
Child:
4:c4d879a39775
Commit message:
Changed the axis readings return normalised signed float; Changed Hello World program to adjust RGB LED

Changed in this revision

MMA8451Q.cpp Show annotated file Show diff for this revision Revisions of this file
MMA8451Q.h Show annotated file Show diff for this revision Revisions of this file
--- a/MMA8451Q.cpp	Thu Oct 11 14:28:23 2012 +0000
+++ b/MMA8451Q.cpp	Fri Oct 12 11:30:34 2012 +0000
@@ -40,19 +40,19 @@
     return who_am_i;
 }
 
-int16_t MMA8451Q::getAccX() {
-    return getAccAxis(REG_OUT_X_MSB);
+float MMA8451Q::getAccX() {
+    return (float(getAccAxis(REG_OUT_X_MSB))/4096.0);
 }
 
-int16_t MMA8451Q::getAccY() {
-    return getAccAxis(REG_OUT_Y_MSB);
+float MMA8451Q::getAccY() {
+    return (float(getAccAxis(REG_OUT_Y_MSB))/4096.0);
 }
 
-int16_t MMA8451Q::getAccZ() {
-    return getAccAxis(REG_OUT_Z_MSB);
+float MMA8451Q::getAccZ() {
+    return (float(getAccAxis(REG_OUT_Z_MSB))/4096.0);
 }
 
-void MMA8451Q::getAccAllAxis(int16_t * res) {
+void MMA8451Q::getAccAllAxis(float * res) {
     res[0] = getAccX();
     res[1] = getAccY();
     res[2] = getAccZ();
--- a/MMA8451Q.h	Thu Oct 11 14:28:23 2012 +0000
+++ b/MMA8451Q.h	Fri Oct 12 11:30:34 2012 +0000
@@ -27,23 +27,22 @@
 * @code
 * #include "mbed.h"
 * #include "MMA8451Q.h"
-*
+* 
 * #define MMA8451_I2C_ADDRESS (0x1d<<1)
-*
+* 
+* MMA8451Q acc(P_E25, P_E24, MMA8451_I2C_ADDRESS);
+* PwmOut rled(LED_RED);
+* PwmOut gled(LED_GREEN);
+* PwmOut bled(LED_BLUE);
+* 
 * int main(void) {
-*    DigitalOut led(LED_GREEN);
-*    MMA8451Q acc(P_E25, P_E24, MMA8451_I2C_ADDRESS);
-*    printf("WHO AM I: 0x%2X\r\n", acc.getWhoAmI());
-*    
-*    while (true) {
-*        printf("-----------\r\n");
-*        printf("acc_x: %d\r\n", acc.getAccX());
-*        printf("acc_y: %d\r\n", acc.getAccY());
-*        printf("acc_z: %d\r\n", acc.getAccZ());
-*        
-*        wait(1);
-*        led = !led;
-*    }
+* 
+*     while (true) {       
+*         rled = 1.0 - abs(acc.getAccX());
+*         gled = 1.0 - abs(acc.getAccY());
+*         bled = 1.0 - abs(acc.getAccZ());
+*         wait(0.1);
+*     }
 * }
 * @endcode
 */
@@ -76,28 +75,28 @@
    *
    * @returns X axis acceleration
    */
-  int16_t getAccX();
+  float getAccX();
 
   /**
    * Get Y axis acceleration
    *
    * @returns Y axis acceleration
    */
-  int16_t getAccY();
+  float getAccY();
 
   /**
    * Get Z axis acceleration
    *
    * @returns Z axis acceleration
    */
-  int16_t getAccZ();
+  float getAccZ();
 
   /**
    * Get XYZ axis acceleration
    *
    * @param res array where acceleration data will be stored
    */
-  void getAccAllAxis(int16_t * res);
+  void getAccAllAxis(float * res);
 
 private:
   I2C m_i2c;