Use of interrupts example for NMHU ambient computing class Sp2015. added MMA8451Q8 library to use as point of departure.
Dependencies: MMA8451Q8b SLCD mbed
Fork of KL46z_all_interrupt by
Diff: main.cpp
- Revision:
- 4:20c499a3f9c9
- Parent:
- 3:53d47a5dbb2c
- Child:
- 5:630a0dd8455a
diff -r 53d47a5dbb2c -r 20c499a3f9c9 main.cpp --- a/main.cpp Tue Feb 03 18:05:52 2015 +0000 +++ b/main.cpp Wed Feb 10 15:31:24 2016 +0000 @@ -37,14 +37,14 @@ #define MMA8451_I2C_ADDRESS (0x1d<<1) Ticker ledBlink; // timinginterrupt for RED led -InterruptIn mybutton(PTC3); //push botton with internal pullup +InterruptIn MMA8451QInt1(PTC5); //MMA8451Q INT1 DigitalOut myled(LED_RED); // red led -DigitalOut relay(LED_GREEN); // green led +DigitalOut green(LED_GREEN); // green led MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); float delay = WAITDELAY; -int relayState = RELAYOFF; +int greenState = RELAYOFF; int outState = false; SLCD slcd; //define LCD display char LCDMessages[2][LCDLEN] = {"TRUE", "FALS"}; @@ -71,8 +71,8 @@ void pressed() // button intterupt { - relayState = !relayState; - relay.write(relayState); + greenState = !greenState; + green.write(greenState); } int main() @@ -83,10 +83,12 @@ char lcdData[LCDLEN]; myled.write(outState); - relay.write(relayState); + green.write(greenState); // set up interrrupts to be used later for taps - mybutton.fall(&pressed); + // set up interrrupts to be used later for taps + MMA8451QInt1.rise(&pressed); + MMA8451QInt1.mode(PullNone); // set up interrrupts to be used later for taps ledBlink.attach(&LEDBlinker, LEDDELAY); @@ -106,7 +108,7 @@ sprintf (lcdData,"%x",regData); LCDMess(lcdData,BLINKTIME); - acc.setPulseConfiguration(latchData, axisData); // write the data + acc.setPulseConfiguration(latchData,axisData); // write the data acc.readRegs(REG_PULSE_CFG, ®Data, 1); // check it sprintf (lcdData,"%x",regData); LCDMess(lcdData,BLINKTIME); @@ -115,7 +117,7 @@ sprintf (lcdData,"%x",regData); LCDMess(lcdData,BLINKTIME); - LCDMessNoDwell(LCDMessages[relayState]); + LCDMessNoDwell(LCDMessages[greenState]); wait(delay); } }