From 0481f5ab0d4fbc8d3b00e3bb9071df87dffe702b Mon Sep 17 00:00:00 2001 From: sieja Date: Thu, 20 Feb 2025 20:29:04 +0100 Subject: [PATCH] =?UTF-8?q?Wska=C5=BAnik=20baterii?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TempHumLoggerHomeKit.ino | 42 +++++++++++++++---- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/ESP32/TempHumLoggerHomeKit/TempHumLoggerHomeKit.ino b/ESP32/TempHumLoggerHomeKit/TempHumLoggerHomeKit.ino index a8714bc..187f887 100644 --- a/ESP32/TempHumLoggerHomeKit/TempHumLoggerHomeKit.ino +++ b/ESP32/TempHumLoggerHomeKit/TempHumLoggerHomeKit.ino @@ -9,7 +9,7 @@ #include "SD.h" #include "SPI.h" -#define Version "menu : 0.1menu" +#define Version "menu : 0.4batt" #define WIRE Wire #define DHTTYPE DHT22 #define DHTPIN 4 @@ -19,6 +19,9 @@ #define BTN_ENTER 34 #define BTN_DOWN 35 #define VOLT_IN 36 +const float voltageDividerFactor = 1.51;//1.56; +const float adcMaxVoltage = 3.3; +const int adcResolution = 4095; Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &WIRE); DHT dht(DHTPIN, DHTTYPE); @@ -44,6 +47,9 @@ int hoursToSet = -1; int adcVoltValue; +float measuredVoltage = 0; +float batteryVoltage = 0; +int batteryBarWidth = 0; char dateString[21]; void setup() { @@ -100,6 +106,8 @@ void setup() { } display.display(); delay(500); +// rtc.adjust(DateTime(2025,2,15, 17, 44,59)); + //setup END } @@ -167,7 +175,7 @@ void loop() { - if (menuL0 == 8 ) { + if (menuL0 == 9 ) { if (digitalRead(BTN_ENTER) == HIGH and menuL1 == 10) { menuL1 = 9; } @@ -275,16 +283,32 @@ void loop() { } } - if (menuL0 == 9 ) { + + + + + if (menuL0 == 8 ) { display.setCursor(0, 0); display.print("MENU TECH"); - adcVoltValue = analogRead(VOLT_IN); // Odczyt wartości ADC z GPIO36 - display.setCursor(0,8); - display.print("ADC:"); - display.setCursor(20, 24); - display.print(adcVoltValue); + adcVoltValue = analogRead(VOLT_IN); // Odczyt wartości ADC z GPIO36 + measuredVoltage = (adcVoltValue * adcMaxVoltage) / adcResolution; + batteryVoltage = (measuredVoltage * voltageDividerFactor)+0.1; + display.setCursor(70,0); + display.print("V:"); + display.setCursor(85, 0); + display.print(batteryVoltage); + display.drawRect(0, 9, 124, 7, SSD1306_WHITE); + display.fillRect(124, 10, 5, 5, SSD1306_WHITE); + batteryBarWidth = (((batteryVoltage-3)/1.2)*122); + if (batteryBarWidth >122){ + batteryBarWidth = 122; + } + display.fillRect(1, 10, batteryBarWidth, 5, SSD1306_WHITE); + if (batteryVoltage < 2 ){ + display.setCursor(60,8); + display.print("xxx"); + } - Serial.println(adcVoltValue); if (digitalRead(BTN_UP) == HIGH) { display.setCursor(0, 24);