From 196d504fa781401eb577849c8d7be9fc1913499b Mon Sep 17 00:00:00 2001 From: Dirk Jahnke Date: Thu, 30 May 2019 20:41:01 +0200 Subject: [PATCH] Fixed led flickering on update -- configurable time between updates --- src/SevenSegmentClock.cpp | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/SevenSegmentClock.cpp b/src/SevenSegmentClock.cpp index 17b0682..6e80a95 100644 --- a/src/SevenSegmentClock.cpp +++ b/src/SevenSegmentClock.cpp @@ -181,22 +181,29 @@ void SevenSegmentClock::displaySeperator(char seperatorCharacter) { } } +static uint32_t lastUpdate_ms = 0; + void SevenSegmentClock::displayTime(int hour, int minute) { char displayText[4]; - clockHour = hour; - clockMinute = minute; - Serial.print("SevenSegmentClock: new time "); Serial.print(clockHour); Serial.print(":"); Serial.println(clockMinute); - displayText[0] = (hour > 9) ? '0' + (hour/10) : ' '; - displayText[1] = '0' + hour % 10; - displayText[2] = '0' + minute / 10; - displayText[3] = '0' + minute % 10; - displayDigit(0, displayText[0]); - displayDigit(1, displayText[1]); - displayDigit(2, displayText[2]); - displayDigit(3, displayText[3]); - displaySeperator(':'); - strip->show(); - Serial.print("Shown: "); Serial.print(displayText[0]); Serial.print(displayText[1]); Serial.print(':'); Serial.print(displayText[2]); Serial.println(displayText[3]); + + if (clockHour != hour || clockMinute != minute || millis()-lastUpdate_ms > TIME_BETWEEN_DISPLAY_UPDATES_ms) { + clockHour = hour; + clockMinute = minute; + Serial.print("SevenSegmentClock: new time "); Serial.print(clockHour); Serial.print(":"); Serial.println(clockMinute); + displayText[0] = (hour > 9) ? '0' + (hour/10) : ' '; + displayText[1] = '0' + hour % 10; + displayText[2] = '0' + minute / 10; + displayText[3] = '0' + minute % 10; + displayDigit(0, displayText[0]); + displayDigit(1, displayText[1]); + displayDigit(2, displayText[2]); + displayDigit(3, displayText[3]); + displaySeperator(':'); + strip->show(); + Serial.print("Shown: "); Serial.print(displayText[0]); Serial.print(displayText[1]); + Serial.print(':'); Serial.print(displayText[2]); Serial.println(displayText[3]); + lastUpdate_ms = millis(); + } }; uint32_t SevenSegmentClock::red, SevenSegmentClock::green, SevenSegmentClock::blue, SevenSegmentClock::white, SevenSegmentClock::black;