Demo program for using MMA8451Q double tap detection and responding to associated interrupt on the FRDM KL25Z board
main.cpp@0:c2d23138786f, 2013-03-10 (annotated)
- Committer:
- JoKer
- Date:
- Sun Mar 10 04:41:35 2013 +0000
- Revision:
- 0:c2d23138786f
MMA8451Q Double Tap and Interrupt example for FRDM KL25Z board
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JoKer | 0:c2d23138786f | 1 | #include "mbed.h" |
JoKer | 0:c2d23138786f | 2 | #include "MMA8451Q.h" |
JoKer | 0:c2d23138786f | 3 | |
JoKer | 0:c2d23138786f | 4 | #define MMA8451_I2C_ADDRESS (0x1d<<1) |
JoKer | 0:c2d23138786f | 5 | #define ON 0 |
JoKer | 0:c2d23138786f | 6 | #define OFF !ON |
JoKer | 0:c2d23138786f | 7 | |
JoKer | 0:c2d23138786f | 8 | //Setup the interrupts for the MMA8451Q |
JoKer | 0:c2d23138786f | 9 | InterruptIn accInt1(PTA14); |
JoKer | 0:c2d23138786f | 10 | InterruptIn accInt2(PTA15);//not used in this prog but this is the other int from the accelorometer |
JoKer | 0:c2d23138786f | 11 | |
JoKer | 0:c2d23138786f | 12 | uint8_t togstat=0;//Led status |
JoKer | 0:c2d23138786f | 13 | DigitalOut bled(LED_BLUE); |
JoKer | 0:c2d23138786f | 14 | |
JoKer | 0:c2d23138786f | 15 | |
JoKer | 0:c2d23138786f | 16 | void tapTrue(void){ |
JoKer | 0:c2d23138786f | 17 | if(togstat == 0){ |
JoKer | 0:c2d23138786f | 18 | togstat = 1; |
JoKer | 0:c2d23138786f | 19 | bled=ON; |
JoKer | 0:c2d23138786f | 20 | } else { |
JoKer | 0:c2d23138786f | 21 | togstat = 0; |
JoKer | 0:c2d23138786f | 22 | bled=OFF; |
JoKer | 0:c2d23138786f | 23 | } |
JoKer | 0:c2d23138786f | 24 | |
JoKer | 0:c2d23138786f | 25 | } |
JoKer | 0:c2d23138786f | 26 | |
JoKer | 0:c2d23138786f | 27 | |
JoKer | 0:c2d23138786f | 28 | int main(void) { |
JoKer | 0:c2d23138786f | 29 | |
JoKer | 0:c2d23138786f | 30 | MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);//accelorometer instance |
JoKer | 0:c2d23138786f | 31 | |
JoKer | 0:c2d23138786f | 32 | acc.setDoubleTap();//Setup the MMA8451Q to look for a double Tap |
JoKer | 0:c2d23138786f | 33 | accInt1.rise(&tapTrue);//call tapTrue when an interrupt is generated on PTA14 |
JoKer | 0:c2d23138786f | 34 | |
JoKer | 0:c2d23138786f | 35 | while (true) { |
JoKer | 0:c2d23138786f | 36 | //Interrupt driven so nothing in main loop |
JoKer | 0:c2d23138786f | 37 | } |
JoKer | 0:c2d23138786f | 38 | } |