From ecf8711e54e4d3f93908062651636fb818088fc1 Mon Sep 17 00:00:00 2001 From: Laurent Claude Date: Tue, 5 Sep 2023 11:19:42 +0200 Subject: [PATCH] =?UTF-8?q?ajustement=20premi=C3=A8re=20seconde=20de=20d?= =?UTF-8?q?=C3=A9compte,=20reprise=20au=20temps=20en=20cours,=20temps=20pa?= =?UTF-8?q?r=20d=C3=A9faut=20=C3=A0=20l'allumage=2012=20sec?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e9272c2..c788fa9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -63,6 +63,7 @@ void setup() { for(;;); // Don't proceed, loop forever } + encoder.setPosition(count); // Clear the buffer display.clearDisplay(); @@ -80,8 +81,9 @@ void loop() { display.setTextSize(6); display.setTextColor(SSD1306_WHITE); // Draw white text unsigned long currentMillis = millis(); + int newPos; - if (statutDecompte) { + if (statutDecompte) { // on est en mode de compte à rebours if (count > 0) { if (currentMillis - LastUpdateTimer >= 1000) { LastUpdateTimer = currentMillis; @@ -95,13 +97,19 @@ void loop() { } else { statutDecompte = 0; + count = encoder.getPosition(); + + display.clearDisplay(); + display.setCursor(0, 20); + display.println(count); + display.display(); } } - else { + else { // on est en mode réglage / pause static int pos = 0; encoder.tick(); - int newPos = encoder.getPosition(); + newPos = encoder.getPosition(); if (pos != newPos) { if (newPos < 0) { newPos = 0; @@ -119,6 +127,12 @@ void loop() { if (digitalRead(ENCROT_BP) && (currentMillis - LastReadBP > 250)){ LastReadBP = currentMillis; statutDecompte = !statutDecompte; + if (statutDecompte) { + LastUpdateTimer = currentMillis; + } + else { + encoder.setPosition(count); + } } digitalWrite(SORTIE_RELAIS, statutDecompte);