Fixed led flickering on update -- configurable time between updates

This commit is contained in:
Dirk Jahnke 2019-05-30 20:41:01 +02:00
parent 831b514c0a
commit 196d504fa7
1 changed files with 21 additions and 14 deletions

View File

@ -181,22 +181,29 @@ void SevenSegmentClock::displaySeperator(char seperatorCharacter) {
} }
} }
static uint32_t lastUpdate_ms = 0;
void SevenSegmentClock::displayTime(int hour, int minute) { void SevenSegmentClock::displayTime(int hour, int minute) {
char displayText[4]; char displayText[4];
clockHour = hour;
clockMinute = minute; if (clockHour != hour || clockMinute != minute || millis()-lastUpdate_ms > TIME_BETWEEN_DISPLAY_UPDATES_ms) {
Serial.print("SevenSegmentClock: new time "); Serial.print(clockHour); Serial.print(":"); Serial.println(clockMinute); clockHour = hour;
displayText[0] = (hour > 9) ? '0' + (hour/10) : ' '; clockMinute = minute;
displayText[1] = '0' + hour % 10; Serial.print("SevenSegmentClock: new time "); Serial.print(clockHour); Serial.print(":"); Serial.println(clockMinute);
displayText[2] = '0' + minute / 10; displayText[0] = (hour > 9) ? '0' + (hour/10) : ' ';
displayText[3] = '0' + minute % 10; displayText[1] = '0' + hour % 10;
displayDigit(0, displayText[0]); displayText[2] = '0' + minute / 10;
displayDigit(1, displayText[1]); displayText[3] = '0' + minute % 10;
displayDigit(2, displayText[2]); displayDigit(0, displayText[0]);
displayDigit(3, displayText[3]); displayDigit(1, displayText[1]);
displaySeperator(':'); displayDigit(2, displayText[2]);
strip->show(); displayDigit(3, displayText[3]);
Serial.print("Shown: "); Serial.print(displayText[0]); Serial.print(displayText[1]); Serial.print(':'); Serial.print(displayText[2]); Serial.println(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; uint32_t SevenSegmentClock::red, SevenSegmentClock::green, SevenSegmentClock::blue, SevenSegmentClock::white, SevenSegmentClock::black;