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:
vsluiter
Date:
Fri May 17 15:14:03 2013 +0000
Parent:
7:70775be9f474
Commit message:
Working demo with mouse, rgb and fader. Board should be powered on 'KL25Z-USB'

Changed in this revision

TSI.lib Show annotated file Show diff for this revision Revisions of this file
USBDevice.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
diff -r 70775be9f474 -r ffab051c58b5 TSI.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TSI.lib	Fri May 17 15:14:03 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/TSI/#1a60ef257879
diff -r 70775be9f474 -r ffab051c58b5 USBDevice.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBDevice.lib	Fri May 17 15:14:03 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/USBDevice/#354942d2fa38
diff -r 70775be9f474 -r ffab051c58b5 main.cpp
--- a/main.cpp	Tue Feb 19 23:46:45 2013 +0000
+++ b/main.cpp	Fri May 17 15:14:03 2013 +0000
@@ -1,18 +1,32 @@
 #include "mbed.h"
+#include "TSISensor.h"
 #include "MMA8451Q.h"
+#include "USBMouse.h"
 
 #define MMA8451_I2C_ADDRESS (0x1d<<1)
 
+
 int main(void) {
+    USBMouse mouse;
+    float pct_tsi = 0;
+    TSISensor tsi;
     MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
     PwmOut rled(LED_RED);
     PwmOut gled(LED_GREEN);
     PwmOut bled(LED_BLUE);
-
+    rled.period_ms(2);
+    bled.period_ms(2);
+    gled.period_ms(2);
     while (true) {
-        rled = 1.0 - abs(acc.getAccX());
-        gled = 1.0 - abs(acc.getAccY());
-        bled = 1.0 - abs(acc.getAccZ());
-        wait(0.1);
+        float accs[3];
+        float pct_tsi_t;
+        pct_tsi_t = tsi.readPercentage();
+        pct_tsi = pct_tsi_t == 0 && pct_tsi > 0.1 ? pct_tsi : pct_tsi_t;
+        acc.getAccAllAxis(accs);
+        rled = 1.0 - (abs(accs[0])*pct_tsi);
+        gled = 1.0 - (abs(accs[1])*pct_tsi);
+        bled = 1.0 - (abs(accs[2])*pct_tsi);
+        mouse.move(accs[0]*10,accs[1]*-10);
+        wait(0.001);
     }
 }