Kevin Sullivan / Mbed 2 deprecated summerlab2020q2_3

Dependencies:   mbed C12832

Files at this revision

API Documentation at this revision

Comitter:
kevinsullivan
Date:
Sat Aug 01 10:39:17 2020 +0000
Parent:
2:2ca58d1b6389
Commit message:
Q3.2.1 debounce

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Jul 27 14:54:36 2020 +0000
+++ b/main.cpp	Sat Aug 01 10:39:17 2020 +0000
@@ -5,34 +5,29 @@
 DigitalOut led(LED1);
 DigitalOut flash(LED4);
 C12832 lcd(p5,p7,p6,p8,p11);
+Timer debounce;
 int i;
 void flip()
 {
-    led = !led; // toggles the led when the joystick button is pressed.
-    i=led;
-    
-}
-int main()
-{
-    joystickcenter.rise(&flip); // attach the function address to the rising edge
-    wire.mode(PullUp); // With this, no external pullup resistor needed
-    wire.rise(&flip); // attach the function address to the rising edge
-    while(1) { // wait around, interrupts will interrupt this!
-        flash = !flash; // turns LED4 on if off, off if on
-        wait(0.5); // the instruction to wait for half-second
-        lcd.locate(0,0);
-        if(i==0) {
-            lcd.locate(0,0);
-            lcd.printf("stand-by             \n\r");
-            wait (0.1);
-            lcd.printf("LED1 = 0 \n\r");
-            wait (0.2);
+    if (debounce.read_ms() > 800) {
+    led = !led; // toggles the led when the joystick button is pressed.          
+    debounce.reset ();
+    i=1;    
+    }
+    }
+    int main() {
+        joystickcenter.rise(&flip); // attach the function address to the rising edge
+        wire.mode(PullUp); // With this, no external pullup resistor needed
+        wire.rise(&flip); // attach the function address to the rising edge
+        debounce.start();
+        while(1) { // wait around, interrupts will interrupt this!
+            flash = !flash; // turns LED4 on if off, off if on
+            wait(0.5); // the instruction to wait for half-second 
+            if(i==1) {
+                lcd.locate(0,0);
+                lcd.printf("button press detected\n\r");           
+                lcd.printf("%d\n\r", debounce.read_ms());        
+            i=0;
+            }
         }
-        if(i==1) {
-            lcd.locate(0,0);
-            lcd.printf("button press detected\n");
-            lcd.printf("LED = 1  \n\r");
-            wait (0.2);
-        }
-    }
-}
\ No newline at end of file
+    }
\ No newline at end of file