debounce based on book

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
avnisha
Date:
Mon Feb 10 20:01:27 2014 +0000
Commit message:
ok

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 e111fc0f3ecb main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Feb 10 20:01:27 2014 +0000
@@ -0,0 +1,38 @@
+#include "mbed.h"
+
+/*
+ * Book - 9.10 (page 198)
+ * 
+ * Switch debounce based on a simple 50ms wait before next event processed
+ * Note - the wait time DEPENDS on your switch. Experiment !!!
+ */
+
+DigitalOut  led1(LED1);
+DigitalOut  led2(LED2);
+InterruptIn button(p12);
+Timer       debounce;
+
+void    rise(void);
+void    fall(void);
+
+int main() {
+    debounce.start();
+    button.rise(&rise);  
+    //button.fall(&fall);    
+}
+
+void    rise() {
+    printf("rise\n");
+    if (debounce.read_ms() > 50) {
+        led1 = !led1;
+        debounce.reset();
+    }
+}
+
+void    fall() {
+    printf("fall\n");
+    if (debounce.read_ms() > 50) {
+        led2 = !led2;
+        debounce.reset();
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r e111fc0f3ecb mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Feb 10 20:01:27 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f
\ No newline at end of file