Modified example of LED / Accelerometer demo. Added TSI for brightness control

Dependencies:   MMA8451Q TSI USBDevice mbed

Fork of FRDM_MMA8451Q by mbed official

Files at this revision

API Documentation at this revision

Comitter:
chris
Date:
Fri Oct 12 11:31:29 2012 +0000
Parent:
2:41db78380a6e
Child:
4:367de1084ea9
Commit message:
Changed axis readings to return a signed normalised float; Changed hello world program to change RGB LED

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	Fri Oct 12 11:02:58 2012 +0000
+++ b/MMA8451Q.lib	Fri Oct 12 11:31:29 2012 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/emilmont/code/MMA8451Q/#7a43c23c04f9
+http://mbed.org/users/emilmont/code/MMA8451Q/#db7126dbd63f
--- a/main.cpp	Fri Oct 12 11:02:58 2012 +0000
+++ b/main.cpp	Fri Oct 12 11:31:29 2012 +0000
@@ -3,18 +3,17 @@
 
 #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: %.3f\r\n", acc.getAccX());
-        printf("acc_y: %.3f\r\n", acc.getAccY());
-        printf("acc_z: %.3f\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);
     }
 }