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 Stanley Cohen

Committer:
scohennm
Date:
Sun Feb 01 19:26:52 2015 +0000
Revision:
2:17a0550771c4
Parent:
1:65b0e488f02a
Child:
3:53d47a5dbb2c
added MMA8451Q8 library to use as point of departure.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:912303e63cbd 1 #include "mbed.h"
scohennm 2:17a0550771c4 2 #include "MMA8451Q8.h"
scohennm 1:65b0e488f02a 3 #include "SLCD.h"
scohennm 1:65b0e488f02a 4 #define RELAYON 0
scohennm 1:65b0e488f02a 5 #define RELAYOFF 1
scohennm 1:65b0e488f02a 6 #define LEDDELAY 0.75
scohennm 1:65b0e488f02a 7 #define WAITDELAY 3.0
bcostm 0:912303e63cbd 8
scohennm 1:65b0e488f02a 9 Ticker ledBlink; // timinginterrupt for RED led
scohennm 1:65b0e488f02a 10 InterruptIn mybutton(PTC3); //push botton with internal pullup
scohennm 1:65b0e488f02a 11 DigitalOut myled(LED_RED); // red led
scohennm 1:65b0e488f02a 12 DigitalOut relay(LED_GREEN); // green led
scohennm 1:65b0e488f02a 13
bcostm 0:912303e63cbd 14
scohennm 1:65b0e488f02a 15 float delay = WAITDELAY;
scohennm 1:65b0e488f02a 16 int relayState = RELAYOFF;
scohennm 1:65b0e488f02a 17 int outState = false;
scohennm 1:65b0e488f02a 18 SLCD slcd; //define LCD display
scohennm 1:65b0e488f02a 19 char LCDMessages[2][10] = {"TRUE", "FALS"};
scohennm 1:65b0e488f02a 20
scohennm 1:65b0e488f02a 21
scohennm 1:65b0e488f02a 22 void LCDMess(char *lMess){
scohennm 1:65b0e488f02a 23 slcd.Home();// message stays till next update
scohennm 1:65b0e488f02a 24 slcd.clear();
scohennm 1:65b0e488f02a 25 slcd.printf(lMess);
scohennm 1:65b0e488f02a 26 }
scohennm 1:65b0e488f02a 27
scohennm 1:65b0e488f02a 28 void LEDBlinker(){ // RED LED interrupt
scohennm 1:65b0e488f02a 29 outState = !outState;
scohennm 1:65b0e488f02a 30 myled.write(outState);
scohennm 1:65b0e488f02a 31 }
scohennm 1:65b0e488f02a 32
scohennm 1:65b0e488f02a 33
scohennm 1:65b0e488f02a 34 void pressed() // button intterupt
bcostm 0:912303e63cbd 35 {
scohennm 1:65b0e488f02a 36 relayState = !relayState;
scohennm 1:65b0e488f02a 37 relay.write(relayState);
bcostm 0:912303e63cbd 38 }
scohennm 1:65b0e488f02a 39
bcostm 0:912303e63cbd 40 int main()
bcostm 0:912303e63cbd 41 {
scohennm 1:65b0e488f02a 42 myled.write(outState);
scohennm 1:65b0e488f02a 43 relay.write(relayState);
bcostm 0:912303e63cbd 44 mybutton.fall(&pressed);
scohennm 1:65b0e488f02a 45 ledBlink.attach(&LEDBlinker, LEDDELAY);
scohennm 1:65b0e488f02a 46 while (true) {
scohennm 1:65b0e488f02a 47 // other things can be put here.
scohennm 1:65b0e488f02a 48 LCDMess(LCDMessages[relayState]);
bcostm 0:912303e63cbd 49 wait(delay);
bcostm 0:912303e63cbd 50 }
bcostm 0:912303e63cbd 51 }