Pulse Detection in z-axis

Dependencies:   MMA8451Q8b SLCD mbed

Revision:
1:65b0e488f02a
Parent:
0:912303e63cbd
Child:
2:17a0550771c4
--- 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);
     }
 }