Rudolf Rumpler / Mbed 2 deprecated La_question3

Dependencies:   mbed C12832

Files at this revision

API Documentation at this revision

Comitter:
rudolf5020
Date:
Sun Aug 16 14:54:21 2020 +0000
Parent:
0:8a4ca94d9fc7
Commit message:
r1

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sat Jul 18 11:33:54 2020 +0000
+++ b/main.cpp	Sun Aug 16 14:54:21 2020 +0000
@@ -1,30 +1,36 @@
 #include "mbed.h"
 #include "C12832.h"
- 
+
 C12832 lcd(p5, p7, p6, p8, p11);
 InterruptIn joystickcenter(p14);
 InterruptIn button(p9);
 DigitalOut led(LED1);
 DigitalOut flash(LED4);
 int i; // variable for flip function.
+Timer debounce;// debounce P14
 
-void flip(){
+void flip()
+{
+    if (debounce.read_ms()>200)// if bigger than 1000 want flip 
     led = !led;
-    i = 1; // toggles the led, when pressing a button connects to p5.
-    }
- 
-int main() {
+    i = 1; 
+    debounce.reset(); 
+}
+
+int main()
+{
     lcd.cls();
     lcd.locate(0,0);
-    button.mode(PullUp); 
+    joystickcenter.rise(&flip);
+    debounce.start();
+    button.mode(PullUp);
     button.rise(&flip);
     while(1) {
         flash = !flash;
-        if( i == 1){
-            lcd.printf("Button pressed");
-            i = 0;
-        }
-        
+        if( i == 1) {
+            lcd.printf("Button pressed");  
+        i = 0;
         wait(0.25);
     }
-}
\ No newline at end of file
+  }
+}