Maurizio Conti
/
accell-FRDMKL25
Using on board MMA8451Q on FRK25
Diff: main.cpp
- Revision:
- 6:71e35394bb3e
- Parent:
- 3:c9a411d4fe64
diff -r 79a16c0a88c1 -r 71e35394bb3e main.cpp --- a/main.cpp Tue Feb 19 23:49:45 2013 +0000 +++ b/main.cpp Tue Feb 04 08:59:38 2014 +0000 @@ -1,19 +1,42 @@ #include "mbed.h" +#include "MMA8451Q.h" + +#define MMA8451_I2C_ADDRESS (0x1d<<1) +#define ON 0 +#define OFF !ON + +//Setup the interrupts for the MMA8451Q +InterruptIn accInt1(PTA14); +InterruptIn accInt2(PTA15);//not used in this prog but this is the other int from the accelorometer + +uint8_t togstat=0;//Led status +DigitalOut bled(LED_BLUE); + +void tapTrue(void){ + printf( "-%d\r\n", togstat ); + togstat = !togstat; + + if(togstat) + bled = 0; + else + bled=1; +} + Ticker tick; DigitalOut led1(LED_RED); DigitalOut led2(LED_GREEN); -void flip() { - led2 = !led2; -} +int main() { + + // Accelerometer + MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS); + acc.setDoubleTap();//Setup the MMA8451Q to look for a double Tap + accInt1.rise(&tapTrue);//call tapTrue when an interrupt is generated on PTA14 -int main() { - tick.attach(&flip, 0.7); // setup ticker to call flip led2 after 0.7 seconds - - // spin in a main loop. - while (true) { - led1 = !led1; - wait (0.3); // flip led1 every 0.3 seconds + while(1) + { + printf("X:%001.2f Y:%001.2f Z:%001.2f\r", acc.getAccX(), acc.getAccY(), acc.getAccZ() ); + wait(0.02); } } \ No newline at end of file