Example program to PWM drive the RGB LED depending on the accelerometer reading

Dependencies:   MMA8451Q mbed

Fork of FRDM_MMA8451Q by Emilio Monti

Committer:
mbed_official
Date:
Tue Feb 19 23:46:45 2013 +0000
Revision:
7:70775be9f474
Parent:
5:bf5becf7469c
Updated to public library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chris 2:41db78380a6e 1 #include "mbed.h"
chris 2:41db78380a6e 2 #include "MMA8451Q.h"
chris 2:41db78380a6e 3
chris 2:41db78380a6e 4 #define MMA8451_I2C_ADDRESS (0x1d<<1)
chris 2:41db78380a6e 5
chris 4:367de1084ea9 6 int main(void) {
emilmont 5:bf5becf7469c 7 MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
emilmont 5:bf5becf7469c 8 PwmOut rled(LED_RED);
emilmont 5:bf5becf7469c 9 PwmOut gled(LED_GREEN);
emilmont 5:bf5becf7469c 10 PwmOut bled(LED_BLUE);
chris 4:367de1084ea9 11
emilmont 5:bf5becf7469c 12 while (true) {
chris 3:f2d3e041d8f2 13 rled = 1.0 - abs(acc.getAccX());
chris 3:f2d3e041d8f2 14 gled = 1.0 - abs(acc.getAccY());
chris 3:f2d3e041d8f2 15 bled = 1.0 - abs(acc.getAccZ());
chris 3:f2d3e041d8f2 16 wait(0.1);
chris 2:41db78380a6e 17 }
chris 2:41db78380a6e 18 }