From f2c1747a44ffbbd6ad81d249d9f8b806435f2b59 Mon Sep 17 00:00:00 2001 From: sieja Date: Thu, 19 Jun 2025 11:58:57 +0200 Subject: [PATCH] Dodawnie zmiany interwalu --- .../TempHumLoggerHomeKit.ino | 147 +++++++++++++----- 1 file changed, 106 insertions(+), 41 deletions(-) diff --git a/ESP32/TempHumLoggerHomeKit/TempHumLoggerHomeKit.ino b/ESP32/TempHumLoggerHomeKit/TempHumLoggerHomeKit.ino index f27e52f..547bd56 100644 --- a/ESP32/TempHumLoggerHomeKit/TempHumLoggerHomeKit.ino +++ b/ESP32/TempHumLoggerHomeKit/TempHumLoggerHomeKit.ino @@ -10,7 +10,7 @@ #include "SD.h" #include "SPI.h" -#define Version "0.47" +#define Version "0.48" #define WIRE Wire #define DHTTYPE DHT22 #define DHTPIN 4 //GPIO04 D4 @@ -84,10 +84,13 @@ int years; //########################################################################################################################## int intervalTempIdx = 3; int intervalTempWrite = 0; +int intervalTempWriteMins = 0; +int intervalTempWriteHours = 0; + int minsToSet = -1; int hoursToSet = -1; - +int intervalToSet = -1; int adcVoltValue; float measuredVoltage = 0; @@ -230,13 +233,13 @@ void setup() { display.setCursor(60, 0); display.println(Version); display.setCursor(0, 8); - if (intervalTempIdx = 1) { + if (intervalTempIdx == 1) { intervalTempWrite = 1; - } else if (intervalTempIdx = 2) { + } else if (intervalTempIdx == 2) { intervalTempWrite = 5; - } else if (intervalTempIdx = 3) { + } else if (intervalTempIdx == 3) { intervalTempWrite = 15; - } else if (intervalTempIdx = 4) { + } else if (intervalTempIdx == 4) { intervalTempWrite = 60; } else { intervalTempWrite = 360; @@ -362,7 +365,7 @@ void setup() { humL = lastHumL; } //setup END - //###################### + //###################################################################################################################################################################### } void loop() { @@ -391,14 +394,13 @@ void loop() { humL = (dhtL.readHumidity() + 1.7); //kalibracja if (isnan(humL)) { humL = lastHumL; } - //########################################################################################################################## - if (intervalTempIdx = 1) { + if (intervalTempIdx == 1) { intervalTempWrite = 1; - } else if (intervalTempIdx = 2) { + } else if (intervalTempIdx == 2) { intervalTempWrite = 5; - } else if (intervalTempIdx = 3) { + } else if (intervalTempIdx == 3) { intervalTempWrite = 15; - } else if (intervalTempIdx = 4) { + } else if (intervalTempIdx == 4) { intervalTempWrite = 60; } else { intervalTempWrite = 360; @@ -469,56 +471,101 @@ void loop() { if (menuL1 == 10) { display.setCursor(0, 8); display.print("Enter edycja czasu"); - display.setCursor(0, 16); - display.print("Intwerwal: "); + display.setCursor(0, 18); + display.print("Inwerwal: "); //########################################################################################################################## - display.print(intervalTempIdx); + + + if (intervalTempIdx == 1) { + intervalTempWrite = 1; + } else if (intervalTempIdx == 2) { + intervalTempWrite = 5; + } else if (intervalTempIdx == 3) { + intervalTempWrite = 15; + } else if (intervalTempIdx == 4) { + intervalTempWrite = 60; + } else { + intervalTempWrite = 360; + } if (intervalTempWrite >= 60) { - display.setCursor(60, 16); - display.print((intervalTempIdx / 60)); - display.setCursor(80, 16); + display.setCursor(60, 18); + display.print((intervalTempWrite / 60)); + display.setCursor(80, 18); display.print("godz"); } else { - display.setCursor(60, 16); - display.print((intervalTempIdx)); - display.setCursor(80, 16); - display.print("godz"); + display.setCursor(60, 18); + display.print((intervalTempWrite)); + display.setCursor(80, 18); + display.print("min"); } } if (menuL1 == 9) { display.setCursor(0, 8); delay(100); - display.print("Interwal:"); + display.print("Ustaw Interwal"); delay(100); + if (digitalRead(BTN_ENTER) == HIGH and menuL2 == 10) { menuL2 = 9; } - //########################################################################################################################## if (menuL2 == 9) { display.setCursor(0, 16); - display.print("Ustaw godziny"); - display.setCursor(45, 16); - display.print(hoursToSet); - delay(100); + display.print("Interwal:"); + display.setCursor(64, 16); + if (intervalToSet == -1) { + intervalToSet = intervalTempIdx; + } + if (intervalToSet == 1) { + intervalTempWrite = 1; + } else if (intervalToSet == 2) { + intervalTempWrite = 5; + } else if (intervalToSet == 3) { + intervalTempWrite = 15; + } else if (intervalToSet == 4) { + intervalTempWrite = 60; + } else { + intervalTempWrite = 360; + } + if (intervalTempWrite >= 60) { + display.setCursor(60, 16); + display.print((intervalTempWrite / 60)); + display.setCursor(80, 16); + display.print("godz"); + } else { + display.setCursor(60, 16); + display.print((intervalTempWrite)); + display.setCursor(80, 16); + display.print("min"); + } + delay(250); if (digitalRead(BTN_ENTER) == HIGH) { - intervalTempWrite++; - if (intervalTempWrite >= 6) { - intervalTempWrite = 1; - } + menuL2 = 10; + intervalTempIdx = intervalToSet; + intervalToSet = -1; } } - if (menuL2 == 8) { + + } + if (menuL1 == 8) { + display.setCursor(0, 8); + display.print("Ustaw godziny"); + + if (digitalRead(BTN_ENTER) == HIGH and menuL2 == 10) { + menuL2 = 9; + } + + if (menuL2 == 9) { display.setCursor(0, 16); display.print("Godzina:"); - display.setCursor(45, 16); + display.setCursor(50, 16); if (hoursToSet == -1) { hoursToSet = now.hour(); } display.print(hoursToSet); - delay(100); + delay(250); if (digitalRead(BTN_ENTER) == HIGH) { // tu ustawianie czasu @@ -528,6 +575,8 @@ void loop() { } } } + + if (menuL1 == 7) { display.setCursor(0, 8); display.print("Ustaw minuty"); @@ -562,7 +611,7 @@ void loop() { } } } - if (menuL1 == 36) { + if (menuL1 == 6) { display.setCursor(0, 8); display.print("Ustaw sekundy na 0"); @@ -583,7 +632,7 @@ void loop() { } } - if (menuL1 == 6) { + if (menuL1 == 5) { display.setCursor(0, 8); display.print("Wyjdz"); if (digitalRead(BTN_ENTER) == HIGH) { @@ -726,13 +775,16 @@ void loop() { if (menuL2 == 9 and hoursToSet < 23) { hoursToSet = hoursToSet + 1; } + if (menuL2 == 9 and intervalToSet < 5) { + intervalToSet = intervalToSet + 1; + } } if (digitalRead(BTN_DOWN) == HIGH and menuL0 >= 7) { if (menuL0 > 7 && menuL1 == 10) { menuL0 = menuL0 - 1; } - if (menuL1 > 6 and menuL1 <= 9 && menuL2 == 10) { + if (menuL1 > 5 and menuL1 <= 9 && menuL2 == 10) { menuL1 = menuL1 - 1; } if (menuL2 > 6 and menuL2 < 9 and menuL0 != 10 and menuL1 != 10) { @@ -744,6 +796,9 @@ void loop() { if (menuL2 == 9 and hoursToSet > 1) { hoursToSet = hoursToSet - 1; } + if (menuL2 == 9 and intervalToSet > 1) { + intervalToSet = intervalToSet - 1; + } } @@ -771,7 +826,7 @@ void loop() { delay(500); } //zapis na SD poziom baterii - if (mins % 1 == 0 && secs == 0) { + if (mins % 1 == 0 && secs == 7) { File file = SD.open("/GeneralLog.txt", FILE_APPEND); if (file) { display.fillRect(0, 0, 128, 64, SSD1306_WHITE); @@ -782,10 +837,20 @@ void loop() { file.println(formatNumber(currentBatteryVoltage, 2)); file.close(); } - } + } + Serial.println("intervalTempWrite"); + Serial.println(intervalTempWrite); + Serial.println("dzielenie"); + Serial.println(mins % intervalTempWrite); //zapis na SD temp i hum - if (mins % intervalTempWrite == 0 && secs == 0) { + if (intervalTempWrite >=360){ + intervalTempWriteHours = (intervalTempWrite/60); + } else { + intervalTempWriteHours = -1; + } + if ((intervalTempWriteHours == -1 && mins % intervalTempWrite == 0) or (intervalTempWriteHours == hourss && mins == 0) && secs == 0){ + // mins % intervalTempWrite == 0 && secs == 0) { File file = SD.open("/TempHumLog.txt", FILE_APPEND); if (file) { display.fillRect(0, 0, 124, 64, SSD1306_WHITE);