Use of interrupts example for NMHU ambient computing class Sp2015. Shows input pin and timer type interrupts.

Dependencies:   SLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
scohennm
Date:
Mon Jan 26 16:43:52 2015 +0000
Parent:
0:912303e63cbd
Commit message:
Use of interrupts example for NMHU ambient computing class Sp2015. Shows input pin and timer type interrupts.

Changed in this revision

SLCD.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 912303e63cbd -r 65b0e488f02a SLCD.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SLCD.lib	Mon Jan 26 16:43:52 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Sissors/code/SLCD/#ef2b3b7f1b01
diff -r 912303e63cbd -r 65b0e488f02a main.cpp
--- a/main.cpp	Fri Feb 21 12:53:03 2014 +0000
+++ b/main.cpp	Mon Jan 26 16:43:52 2015 +0000
@@ -1,23 +1,51 @@
 #include "mbed.h"
+
+#include "SLCD.h"
+#define RELAYON 0
+#define RELAYOFF 1
+#define LEDDELAY 0.75
+#define WAITDELAY 3.0
  
-InterruptIn mybutton(USER_BUTTON);
-DigitalOut myled(LED1);
- 
-float delay = 1.0; // 1 sec
+Ticker ledBlink; // timinginterrupt for RED led
+InterruptIn mybutton(PTC3);  //push botton with internal pullup
+DigitalOut myled(LED_RED); // red led
+DigitalOut relay(LED_GREEN); // green led
+
  
-void pressed()
+float delay = WAITDELAY;
+int relayState = RELAYOFF;
+int outState = false;
+SLCD slcd; //define LCD display
+char LCDMessages[2][10] = {"TRUE", "FALS"};
+
+
+void LCDMess(char *lMess){
+        slcd.Home();// message stays till next update
+        slcd.clear();
+        slcd.printf(lMess);
+}
+
+void LEDBlinker(){  // RED LED interrupt
+    outState = !outState; 
+    myled.write(outState);
+}
+        
+    
+void pressed() // button intterupt
 {
-    if (delay == 1.0)
-        delay = 0.2; // 200 ms
-    else
-        delay = 1.0; // 1 sec
+    relayState = !relayState;
+    relay.write(relayState);
 }
- 
+
 int main()
 {
+    myled.write(outState);
+    relay.write(relayState);
     mybutton.fall(&pressed);
-    while (1) {
-        myled = !myled;
+    ledBlink.attach(&LEDBlinker, LEDDELAY);
+    while (true) { 
+    // other things can be put here.  
+        LCDMess(LCDMessages[relayState]);  
         wait(delay);
     }
 }
diff -r 912303e63cbd -r 65b0e488f02a mbed.bld
--- a/mbed.bld	Fri Feb 21 12:53:03 2014 +0000
+++ b/mbed.bld	Mon Jan 26 16:43:52 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/ed8466a608b4
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/04dd9b1680ae
\ No newline at end of file