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

Dependencies:   MMA8451Q TSI USBDevice mbed

Fork of FRDM_MMA8451Q by mbed official

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "TSISensor.h"
00003 #include "MMA8451Q.h"
00004 #include "USBMouse.h"
00005 
00006 #define MMA8451_I2C_ADDRESS (0x1d<<1)
00007 
00008 
00009 int main(void) {
00010     USBMouse mouse;
00011     float pct_tsi = 0;
00012     TSISensor tsi;
00013     MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
00014     PwmOut rled(LED_RED);
00015     PwmOut gled(LED_GREEN);
00016     PwmOut bled(LED_BLUE);
00017     rled.period_ms(2);
00018     bled.period_ms(2);
00019     gled.period_ms(2);
00020     while (true) {
00021         float accs[3];
00022         float pct_tsi_t;
00023         pct_tsi_t = tsi.readPercentage();
00024         pct_tsi = pct_tsi_t == 0 && pct_tsi > 0.1 ? pct_tsi : pct_tsi_t;
00025         acc.getAccAllAxis(accs);
00026         rled = 1.0 - (abs(accs[0])*pct_tsi);
00027         gled = 1.0 - (abs(accs[1])*pct_tsi);
00028         bled = 1.0 - (abs(accs[2])*pct_tsi);
00029         mouse.move(accs[0]*10,accs[1]*-10);
00030         wait(0.001);
00031     }
00032 }