fix display

This commit is contained in:
Dejvino 2026-02-12 21:25:53 +01:00
parent daa3cff439
commit 5bf3870869

View File

@ -34,7 +34,7 @@ const int VIBRATION_PIN = 4;
// OLED display settings
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define SCREEN_HEIGHT 32
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C
#ifdef ENABLE_DISPLAY
@ -67,7 +67,9 @@ unsigned long lightLowStartTime = 0;
String displayData[4];
int currentDisplayLine = 0;
unsigned long lastDisplayScrollTime = 0;
const unsigned long DISPLAY_SCROLL_INTERVAL = 1000; // 1000 = 1 second
const unsigned long DISPLAY_SCROLL_INTERVAL = 2000; // 1000 = 1 second
const int displayTextLines = 5;
int displayDataLines = displayTextLines;
#endif
// Notification queue
@ -76,7 +78,8 @@ String queuedTitle = "";
String queuedPriority = "";
void setup() {
Serial.begin(115200);
Serial.begin(9600);
Serial.println("Setup started.");
#if defined(ENABLE_SENSORS) || defined(ENABLE_DISPLAY)
Wire.begin();
@ -129,6 +132,9 @@ void setup() {
display.display();
delay(1000);
#endif
Serial.println("Setup finished.");
}
bool sendNotification(String message, String title, String priority);
@ -242,6 +248,7 @@ void loop() {
displayData[1] = "Light: " + String(currentLightLevel) + " lx";
displayData[2] = "Light Active: " + String(isLightActive ? "ON" : "OFF");
displayData[3] = "Device: " + String(isDeviceActive ? "ACTIVE" : "INACTIVE");
displayDataLines = 4;
// Update display
updateDisplay();
@ -285,9 +292,9 @@ void updateDisplay() {
unsigned long currentTime = millis();
// Scroll logic
if (currentTime - lastDisplayScrollTime > DISPLAY_SCROLL_INTERVAL) {
if ((displayDataLines > displayTextLines) && (currentTime - lastDisplayScrollTime > DISPLAY_SCROLL_INTERVAL)) {
lastDisplayScrollTime = currentTime;
currentDisplayLine = (currentDisplayLine + 1) % 4;
currentDisplayLine = (currentDisplayLine + 1) % displayDataLines;
}
display.clearDisplay();
@ -295,8 +302,8 @@ void updateDisplay() {
display.setTextColor(WHITE);
display.setCursor(0, 0);
for (int i = 0; i < 4; i++) {
int lineIndex = (currentDisplayLine + i) % 4;
for (int i = 0; i < displayDataLines; i++) {
int lineIndex = (currentDisplayLine + i) % displayDataLines;
display.println(displayData[lineIndex]);
}