Dependencies:   beep mbed

Files at this revision

API Documentation at this revision

Comitter:
lauram
Date:
Wed Aug 06 21:14:22 2014 +0000
Child:
1:f3758be6979d
Commit message:
starting

Changed in this revision

beep.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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/beep.lib	Wed Aug 06 21:14:22 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/dreschpe/code/beep/#d8e14429a95f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Aug 06 21:14:22 2014 +0000
@@ -0,0 +1,62 @@
+#include "mbed.h"
+#include "beep.h"
+
+Serial PC(USBTX, USBRX);
+InterruptIn pir(D5);
+InterruptIn on(D7);
+InterruptIn off(D6);
+Beep buzzer(D9);
+
+int flagOn,flagOff,flagPIR=0;
+int i = 0;
+int alarmOn=0;  //State (on/off)
+
+void  onInterrupt() 
+{
+    flagOn=1;
+}
+
+void  offInterrupt()
+{
+    flagOff=1;
+}
+
+void pirInterrupt()
+{
+    flagPIR=1;
+}
+
+int main()
+{
+    // on/off interrupts init          
+    on.rise(&onInterrupt);
+    off.rise(&offInterrupt);    
+    
+    // pir sensor interrupt init
+    pir.rise(&pirInterrupt);
+    
+    // start
+    PC.printf("Working... ");
+    while (1) {
+        if (flagOn) {
+            PC.printf("Alarm on ");
+            alarmOn=1;
+            flagOn = 0; //clear flag
+        }
+        
+        if (flagOff) {
+            PC.printf("Alarm off ");
+            alarmOn=0;
+            buzzer.beep(0,0); //Frec(Hz),Time(Sec)
+            flagOff = 0; //clear flag
+        }
+
+        if (flagPIR) {
+            if (alarmOn){
+                buzzer.beep(1000,10); //Frec(Hz),Time(Sec)
+            }
+            flagPIR=0;  //clear flag
+        }
+        __wfi(); //waiting for interrupt 
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Aug 06 21:14:22 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/6213f644d804
\ No newline at end of file