Neil McLoughlin / Mbed 2 deprecated lab_digital_interrupts

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
ellieoin
Date:
Sat Aug 15 20:32:17 2020 +0000
Parent:
0:c24760f7606a
Commit message:
lad_digital_interrupts complete implemetnation with debouncing

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sat Aug 15 19:14:44 2020 +0000
+++ b/main.cpp	Sat Aug 15 20:32:17 2020 +0000
@@ -11,24 +11,49 @@
 InterruptIn btn_center(BTN_CENTER);
 InterruptIn btn_up(BTN_UP);
 InterruptIn btn_right(BTN_RIGHT);
+Timer timer;
+void isr1() {
+
+}
 
 void print_down() {
-    printf("DOWN\n");
+    if (timer.read_ms() > 200) {
+        printf("DOWN\n");
+        timer.reset();
+    }
 }
 void print_left() {
-    printf("LEFT\n");
+    if (timer.read_ms() > 200) {
+        printf("LEFT\n");
+        timer.reset();
+    }
 }
 void print_center() {
-    printf("CENTER\n");
+    if (timer.read_ms() > 200) {
+        printf("CENTER\n");
+        timer.reset();
+    }
 }
 void print_up() {
-    printf("UP\n");
+    if (timer.read_ms() > 200) {
+        printf("UP\n");
+        timer.reset();
+    }
 }
 void print_right() {
-    printf("RIGHT\n");
+    if (timer.read_ms() > 200) {
+        printf("RIGHT\n");
+        timer.reset();
+    }
 }
 
 int main() {
+    btn_down.mode(PullUp);
+    btn_left.mode(PullUp);
+    btn_center.mode(PullUp);
+    btn_up.mode(PullUp);
+    btn_right.mode(PullUp);
+    wait(.001);
     while (1) {
         btn_down.rise(callback(&print_down));
         btn_left.rise(callback(&print_left));
@@ -36,4 +61,4 @@
         btn_up.rise(callback(&print_up));
         btn_right.rise(callback(&print_right));
     }
-}
+}
\ No newline at end of file