From 86d5bcc729de5f3fbf4f0f816bd41a0940e2905c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomislav=20Kopi=C4=87?= Date: Sat, 9 Nov 2024 07:54:39 +0100 Subject: [PATCH] General improvements --- src/main.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index be871ba..618e5d0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -42,6 +42,9 @@ void initSystems() { pinMode(PIN_BUZZER, OUTPUT); pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, HIGH); + Wire.begin(); // Initialize I2C + Wire.setClock(400000); // Set I2C to Fast Mode (400 kHz) + // Initialize the SSD1306 display if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Adjust I2C address if needed for(;;); // Don't proceed, loop forever @@ -242,7 +245,7 @@ bool fetchWeatherData() { int scrollPos = SCREEN_WIDTH; // Global variable to keep track of the scroll position unsigned long lastScrollTime = 0; // To control the scroll speed -const int scrollDelay = 40; // Delay in milliseconds between scroll updates +const int scrollDelay = 30; // Delay in milliseconds between scroll updates void displayWeatherData() { display.clearDisplay(); @@ -311,6 +314,8 @@ void setup(void) { void loop() { timeClient.update(); + commonButtonHandler(); + displayWeatherData(); if (display_override && (millis() - lastDisplayOverride > displayOverrideTimeout)){ display_override = false; lastDisplayOverride = millis(); @@ -319,7 +324,5 @@ void loop() { fetchWeatherData(); lastWeatherUpdate = millis(); } - displayWeatherData(); powerSaveCheck(); - commonButtonHandler(); }