Example using a PIR sensor

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
sam_grove
Date:
Fri Aug 15 23:18:16 2014 +0000
Commit message:
Initial commit

Changed in this revision

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/main.cpp	Fri Aug 15 23:18:16 2014 +0000
@@ -0,0 +1,25 @@
+
+#include "mbed.h"
+
+InterruptIn motion(D2);
+
+int motion_detected = 0;
+
+void irq_handler(void)
+{
+    motion_detected = 1;
+}
+    
+int main(void)
+{
+    int cnt = 0;
+    motion.rise(&irq_handler);
+    
+    while(1) {
+        if(motion_detected) {
+            cnt++;
+            motion_detected = 0;
+            printf("Hello! I've detected %d times since reset\n", cnt);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Aug 15 23:18:16 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9327015d4013
\ No newline at end of file