Using on board MMA8451Q on FRK25

Dependencies:   MMA8451Q mbed

Committer:
mconti
Date:
Tue Feb 04 08:59:38 2014 +0000
Revision:
6:71e35394bb3e
Parent:
3:c9a411d4fe64
Primo commit;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chris 0:5e8c7a36cb58 1 #include "mbed.h"
mconti 6:71e35394bb3e 2 #include "MMA8451Q.h"
mconti 6:71e35394bb3e 3
mconti 6:71e35394bb3e 4 #define MMA8451_I2C_ADDRESS (0x1d<<1)
mconti 6:71e35394bb3e 5 #define ON 0
mconti 6:71e35394bb3e 6 #define OFF !ON
mconti 6:71e35394bb3e 7
mconti 6:71e35394bb3e 8 //Setup the interrupts for the MMA8451Q
mconti 6:71e35394bb3e 9 InterruptIn accInt1(PTA14);
mconti 6:71e35394bb3e 10 InterruptIn accInt2(PTA15);//not used in this prog but this is the other int from the accelorometer
mconti 6:71e35394bb3e 11
mconti 6:71e35394bb3e 12 uint8_t togstat=0;//Led status
mconti 6:71e35394bb3e 13 DigitalOut bled(LED_BLUE);
mconti 6:71e35394bb3e 14
mconti 6:71e35394bb3e 15 void tapTrue(void){
mconti 6:71e35394bb3e 16 printf( "-%d\r\n", togstat );
mconti 6:71e35394bb3e 17 togstat = !togstat;
mconti 6:71e35394bb3e 18
mconti 6:71e35394bb3e 19 if(togstat)
mconti 6:71e35394bb3e 20 bled = 0;
mconti 6:71e35394bb3e 21 else
mconti 6:71e35394bb3e 22 bled=1;
mconti 6:71e35394bb3e 23 }
mconti 6:71e35394bb3e 24
chris 0:5e8c7a36cb58 25
chris 0:5e8c7a36cb58 26 Ticker tick;
chris 0:5e8c7a36cb58 27 DigitalOut led1(LED_RED);
chris 0:5e8c7a36cb58 28 DigitalOut led2(LED_GREEN);
chris 0:5e8c7a36cb58 29
mconti 6:71e35394bb3e 30 int main() {
mconti 6:71e35394bb3e 31
mconti 6:71e35394bb3e 32 // Accelerometer
mconti 6:71e35394bb3e 33 MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
mconti 6:71e35394bb3e 34 acc.setDoubleTap();//Setup the MMA8451Q to look for a double Tap
mconti 6:71e35394bb3e 35 accInt1.rise(&tapTrue);//call tapTrue when an interrupt is generated on PTA14
chris 0:5e8c7a36cb58 36
mconti 6:71e35394bb3e 37 while(1)
mconti 6:71e35394bb3e 38 {
mconti 6:71e35394bb3e 39 printf("X:%001.2f Y:%001.2f Z:%001.2f\r", acc.getAccX(), acc.getAccY(), acc.getAccZ() );
mconti 6:71e35394bb3e 40 wait(0.02);
chris 0:5e8c7a36cb58 41 }
chris 2:b085bc47e75b 42 }