From 52726c263c0f0d42428e1992c82bbe3bb828aaa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomislav=20Kopi=C4=87?= Date: Mon, 11 Nov 2024 19:51:40 +0100 Subject: [PATCH] Add nerdy messages and display brightness --- src/main.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a4c2ccf..e11cb69 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,6 +22,7 @@ NTPClient timeClient(ntpUDP, "pool.ntp.org", 3600, 43200000); // Define these in config.h const String Location = LOCATION; const String API_Key = API_KEY; +int displayBrightness = 205; void beep(int buzz) { tone(PIN_BUZZER, buzz, 100); @@ -38,7 +39,8 @@ void initSystems() { digitalWrite(LED_BUILTIN, HIGH); Wire.begin(); // Initialize I2C Wire.setClock(400000L); // Set I2C to Fast Mode (400 kHz) - + display.ssd1306_command(SSD1306_SETCONTRAST); + display.ssd1306_command(displayBrightness); // Value between 0 and 255 // Initialize the SSD1306 display if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Adjust I2C address if needed for(;;); // Don't proceed, loop forever @@ -83,6 +85,13 @@ void commonButtonHandler() { if (!leftBeeped) { beep(1000); // Play beep sound leftBeeped = true; // Set beeped state + displayBrightness -= 50; + if (displayBrightness < 10 ) { + displayBrightness = 255; + } + // Send the command to set the contrast + display.ssd1306_command(SSD1306_SETCONTRAST); + display.ssd1306_command(displayBrightness); // Value between 0 and 255 // Handle left short press action here } } @@ -96,6 +105,7 @@ void commonButtonHandler() { if (!middleBeeped) { beep(1000); // Play beep sound middleBeeped = true; // Set beeped state + lastWeatherUpdate = millis() + weatherUpdateInterval + 1; // Handle middle short press action here } } @@ -135,7 +145,6 @@ void commonButtonHandler() { if (!middleBeeped) { beep(1000); // Play beep sound middleBeeped = true; // Set beeped state - lastWeatherUpdate += weatherUpdateInterval; // Handle middle long press action here } } @@ -373,7 +382,7 @@ void displayWeatherData() { // If the text has completely scrolled off, reset scroll position to start from the right if (scrollPos < -stateWidth) { scrollPos = SCREEN_WIDTH; - delay(3000); + delay(4000); } } } @@ -426,6 +435,7 @@ void loop() { if (!is_display_off && (millis() - lastWeatherUpdate > weatherUpdateInterval)) { fetchWeatherData(); lastWeatherUpdate = millis(); + scrollPos = SCREEN_WIDTH; } powerSaveCheck(); }