Polling

Revision:
2:b361071cc219
Parent:
1:ed1145480f4b
diff -r ed1145480f4b -r b361071cc219 main.cpp
--- a/main.cpp	Sun Nov 01 16:29:35 2020 +0000
+++ b/main.cpp	Mon Nov 09 15:49:21 2020 +0000
@@ -1,29 +1,17 @@
 #include "mbed.h"
-//
-// test   led rouge et joystick DOWN et affichage sur terminal 
-// GR 2020
-// Universite Paris-Saclay - IUT Cachan
-//
-//
-#define TEMPO1 0.5
-#define TEMPO2 0.1
-Serial pc(USBTX, USBRX);  // Nucleo RX : PA_2 ; TX : PA_3
-DigitalOut ledr(PB_4);  //LED_red  Arduino D5
-DigitalIn DOWN(PB_0);  //joystick down  Arduino A3
-
+// scrutation
+DigitalOut ledr(PB_4);//LED_red 
+DigitalIn DOWN(PB_0); //joystick down
 int main()
 {
-    float t;
-    pc.printf("LED clignotante deux vitesse \r\n");
-    ledr=1;
+    unsigned char DOWN_P=0;
+    ledr=1; // led r eteinte
     while(1) {
-        if(DOWN) t=TEMPO2;
-        else t=TEMPO1;
-        ledr = 0; // OFF
-        wait(t);
-        ledr = 1; // ON
-        wait(t);
-        pc.printf("periode %3.1f \r\n", 2*t);
+        if(DOWN && !DOWN_P) {
+            ledr=!ledr;  
+        }
+        DOWN_P=DOWN;
+        wait(0.01);
     }
 }