This commit is contained in:
Dirk Jahnke 2019-06-03 15:18:10 +02:00
commit 88e480716a
3 changed files with 104 additions and 21 deletions

View File

@ -172,32 +172,104 @@ void SevenSegmentClock::displaySeperator(char seperatorCharacter) {
strip->setPixelColor(clockSeperatorLed2, currentColor); strip->setPixelColor(clockSeperatorLed2, currentColor);
break; break;
default: default:
Serial.print("SevenSegmentClock::displaySeperator: Unknown character to be displayed: ");
Serial.println(seperatorCharacter);
case ' ':
case 0:
strip->setPixelColor(decimalPointLed, black); strip->setPixelColor(decimalPointLed, black);
strip->setPixelColor(clockSeperatorLed1, black); strip->setPixelColor(clockSeperatorLed1, black);
strip->setPixelColor(clockSeperatorLed2, black); strip->setPixelColor(clockSeperatorLed2, black);
Serial.print("SevenSegmentClock::displaySeperator: Unknown character to be displayed: ");
Serial.println(seperatorCharacter);
break; break;
} }
} }
void SevenSegmentClock::displayTime(int hour, int minute) { void SevenSegmentClock::displayTime(int hour, int minute) {
char displayText[4];
clockHour = hour; clockHour = hour;
clockMinute = minute; clockMinute = minute;
Serial.print("SevenSegmentClock: new time "); Serial.print(clockHour); Serial.print(":"); Serial.println(clockMinute); Serial.print("SevenSegmentClock: new time ");
Serial.print(clockHour); Serial.print(":"); Serial.println(clockMinute);
displayUpdate();
};
void SevenSegmentClock::displayUpdate(void) {
char displayText[4];
static int lastHour=0, lastMinute=0;
static uint32_t lastUpdate_ms = 0;
static uint32_t nextBlinkSwitch_ms = 0;
static boolean currentlyBlinkOn = false;
if (clockHour != lastHour || clockMinute != lastMinute || millis()-lastUpdate_ms > TIME_BETWEEN_DISPLAY_UPDATES_ms) {
lastHour = clockHour;
lastMinute = clockMinute;
displayText[0] = (hour > 9) ? '0' + (hour/10) : ' '; displayText[0] = (hour > 9) ? '0' + (hour/10) : ' ';
displayText[1] = '0' + hour % 10; displayText[1] = '0' + hour % 10;
displayText[2] = '0' + minute / 10; displayText[2] = '0' + minute / 10;
displayText[3] = '0' + minute % 10; displayText[3] = '0' + minute % 10;
switch (blinkMode) {
case NoBlinking:
displayDigit(0, displayText[0]); displayDigit(0, displayText[0]);
displayDigit(1, displayText[1]); displayDigit(1, displayText[1]);
displayDigit(2, displayText[2]); displayDigit(2, displayText[2]);
displayDigit(3, displayText[3]); displayDigit(3, displayText[3]);
displaySeperator(':'); displaySeperator(':');
break;
case ClockBlinking:
if (currentlyBlinkOn) {
displayDigit(0, displayText[0]);
displayDigit(1, displayText[1]);
displayDigit(2, displayText[2]);
displayDigit(3, displayText[3]);
displaySeperator(':');
} else {
displayDigit(0, ' ');
displayDigit(1, ' ');
displayDigit(2, ' ');
displayDigit(3, ' ');
displaySeperator(' ');
}
if (millis() > nextBlinkSwitch_ms) {
currentlyBlinkOn = !currentlyBlinkOn;
nextBlinkSwitch_ms = millis() + (currentlyBlinkOn ? BLINK_ON_TIME_ms : BLINK_OFF_TIME_ms);
}
break;
case SeperatorBlinking:
displayDigit(0, displayText[0]);
displayDigit(1, displayText[1]);
displayDigit(2, displayText[2]);
displayDigit(3, displayText[3]);
if (currentlyBlinkOn) {
displaySeperator(':');
} else {
displaySeperator(' ');
}
if (millis() > nextBlinkSwitch_ms) {
currentlyBlinkOn = !currentlyBlinkOn;
nextBlinkSwitch_ms = millis() + (currentlyBlinkOn ? BLINK_ON_TIME_ms : BLINK_OFF_TIME_ms);
}
break;
case DecimalPointBlinking:
displayDigit(0, displayText[0]);
displayDigit(1, displayText[1]);
displayDigit(2, displayText[2]);
displayDigit(3, displayText[3]);
if (currentlyBlinkOn) {
displaySeperator('.');
} else {
displaySeperator(' ');
}
if (millis() > nextBlinkSwitch_ms) {
currentlyBlinkOn = !currentlyBlinkOn;
nextBlinkSwitch_ms = millis() + (currentlyBlinkOn ? BLINK_ON_TIME_ms : BLINK_OFF_TIME_ms);
}
break;
}
strip->show(); strip->show();
Serial.print("Shown: "); Serial.print(displayText[0]); Serial.print(displayText[1]); Serial.print(':'); Serial.print(displayText[2]); Serial.println(displayText[3]); 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;
uint8_t SevenSegmentClock::LedDataPin; uint8_t SevenSegmentClock::LedDataPin;

View File

@ -5,7 +5,8 @@
// avoid flickering of the display: // avoid flickering of the display:
#define TIME_BETWEEN_DISPLAY_UPDATES_ms 300 #define TIME_BETWEEN_DISPLAY_UPDATES_ms 300
#define BLINK_ON_OFF_TIME_ms 1000 #define BLINK_OFF_TIME_ms 600
#define BLINK_ON_TIME_ms 400
#define defaultLedDataPin 2 #define defaultLedDataPin 2
class SevenSegmentClock { class SevenSegmentClock {
public: public:
@ -13,7 +14,10 @@ public:
SevenSegmentClock(uint8_t dataPin) { LedDataPin=dataPin; init(); }; SevenSegmentClock(uint8_t dataPin) { LedDataPin=dataPin; init(); };
void begin(void); void begin(void);
void displayTime(int hour, int minute); void displayTime(int hour, int minute);
void displayUpdate(void);
//void setClockSpeed(int _msPerModelSecond) { msPerModelSecond = _msPerModelSecond; setClockSpeed("x"); }; //void setClockSpeed(int _msPerModelSecond) { msPerModelSecond = _msPerModelSecond; setClockSpeed("x"); };
enum BlinkMode { NoBlinking, ClockBlinking, SeperatorBlinking, DecimalPointBlinking };
void setBlinkMode(BlinkMode _blinkMode) { blinkMode = _blinkMode; };
void setClockHalted(bool halted) { clockHalted = halted; }; void setClockHalted(bool halted) { clockHalted = halted; };
static uint32_t red, green, blue, white, black; static uint32_t red, green, blue, white, black;
enum ClockDisplayStatus { Off, Booting, Halted, StandardClock, FastClock }; enum ClockDisplayStatus { Off, Booting, Halted, StandardClock, FastClock };
@ -23,6 +27,7 @@ private:
void init(void) { displayStatus = Off; clockHour=12; clockMinute=34; setClockHalted(true); }; void init(void) { displayStatus = Off; clockHour=12; clockMinute=34; setClockHalted(true); };
static uint8_t LedDataPin; static uint8_t LedDataPin;
static Adafruit_NeoPixel *strip; static Adafruit_NeoPixel *strip;
static BlinkMode blinkMode;
ClockDisplayStatus displayStatus; ClockDisplayStatus displayStatus;
int clockHour; int clockHour;
int clockMinute; int clockMinute;

View File

@ -181,11 +181,17 @@ void setup() {
} }
int hours = 0, minutes = 0; int hours = 0, minutes = 0;
uint32_t nextUpdate_ms = 0;
void loop() { void loop() {
sevenSegmentClock.displayTime(hours, minutes++); if (millis() > nextUpdate_ms) {
nextUpdate_ms = millis() + 1000;
minutes++;
if (minutes > 99) { minutes = 0; } if (minutes > 99) { minutes = 0; }
if (minutes % 5 == 0) hours++; if (minutes % 5 == 0) hours++;
if (hours > 99) hours = 0; if (hours > 99) hours = 0;
delay(1000); sevenSegmentClock.displayTime(hours, minutes);
if (hours % 4 == 0) sevenSegmentClock.setBlinkMode(SeperatorBlinking); else sevenSegmentClock.setBlinkMode(NoBlinking);
}
sevenSegmentClock.displayUpdate();
} }