From ffa4c5b006cc000e939771014f5422883d34ee73 Mon Sep 17 00:00:00 2001 From: Laurent Claude Date: Sun, 3 Sep 2023 20:36:52 +0200 Subject: [PATCH] #fix action BP --- src/main.cpp | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 150138b..e9272c2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,16 +14,13 @@ #define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); -#define SDA 4 -#define SCL 5 +//#define SDA 4 +//#define SCL 5 -#define SORTIE_RELAIS 1 -#define LED_FLASH 4 -//#define LED_BUILTIN 33 - -#define ENCROT_A 2 -#define ENCROT_B 0 -#define ENCROT_BP 3 +#define SORTIE_RELAIS 16 +#define ENCROT_A 12 +#define ENCROT_B 13 +#define ENCROT_BP 14 // Setup a RotaryEncoder with 2 steps per latch for the 2 signal input pins: RotaryEncoder encoder(ENCROT_A, ENCROT_B, RotaryEncoder::LatchMode::TWO03); @@ -31,8 +28,8 @@ RotaryEncoder encoder(ENCROT_A, ENCROT_B, RotaryEncoder::LatchMode::TWO03); // durée par défaut en secondes int count = 12; -bool decompteStatut = false; -unsigned long LastUpdate = 0; +bool statutDecompte = 0; +unsigned long LastUpdateTimer = 0; unsigned long LastReadBP = 0; #define LOGO_HEIGHT 32 @@ -84,12 +81,12 @@ void loop() { display.setTextColor(SSD1306_WHITE); // Draw white text unsigned long currentMillis = millis(); - if (decompteStatut) { + if (statutDecompte) { if (count > 0) { - if (currentMillis - LastUpdate >= 1000) { - --count; - LastUpdate = currentMillis; + if (currentMillis - LastUpdateTimer >= 1000) { + LastUpdateTimer = currentMillis; + --count; display.clearDisplay(); display.setCursor(0, 20); display.println(count); @@ -97,7 +94,7 @@ void loop() { } } else { - decompteStatut = 0; + statutDecompte = 0; } } else { @@ -119,10 +116,10 @@ void loop() { } // if } - if (!digitalRead(ENCROT_BP) && (LastReadBP - currentMillis > 250)){ + if (digitalRead(ENCROT_BP) && (currentMillis - LastReadBP > 250)){ LastReadBP = currentMillis; - decompteStatut = !decompteStatut; + statutDecompte = !statutDecompte; } - digitalWrite(SORTIE_RELAIS, decompteStatut); + digitalWrite(SORTIE_RELAIS, statutDecompte); } \ No newline at end of file