Uses a reed switch to detect door state

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
User_4574
Date:
Sat Jan 15 13:48:53 2011 +0000
Commit message:
Initial Revision

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
diff -r 000000000000 -r bc6628a89f6b main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Jan 15 13:48:53 2011 +0000
@@ -0,0 +1,41 @@
+#include "mbed.h"
+
+Timer t;
+DigitalOut idle(LED1);
+DigitalOut busy(LED2);
+DigitalOut open(p10);
+InterruptIn start(p15);
+Serial pc(USBTX, USBRX);
+
+int led=0;
+
+void onfall() {
+    pc.printf("Door Opened... ");
+    t.start();
+    open=1;
+    idle=0;
+    led=1;
+}
+
+void onrise() {
+    t.stop();
+    open=0;
+    pc.printf("Door Closed at %f\r\n", t.read());
+    t.reset();
+    busy=0;
+    led=0;
+}
+
+int main() {
+    open=busy=idle=0;
+    start.fall(&onfall);
+    start.rise(&onrise);
+    while(1) {
+        if(led) {
+            busy = !busy;
+        } else {
+            idle = !idle;
+        }
+        wait(1);
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r bc6628a89f6b mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Jan 15 13:48:53 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e