improving clock modes
This commit is contained in:
parent
45a7ffb513
commit
69cded525a
27
constants.h
27
constants.h
@ -32,7 +32,7 @@ const CRGB off = CRGB(0, 0, 0);
|
|||||||
// Default clock face colors
|
// Default clock face colors
|
||||||
// red, orange, yellow, green, cyan, blue, magenta, and white are acceptable, along with CRGB(r, g, b)
|
// red, orange, yellow, green, cyan, blue, magenta, and white are acceptable, along with CRGB(r, g, b)
|
||||||
const int colorSchemeCount = 7;
|
const int colorSchemeCount = 7;
|
||||||
const CRGB colorSchemes[colorSchemeCount][4] = {
|
const CRGB colorSchemes[colorSchemeCount][3] = {
|
||||||
{red, // Color for hour display
|
{red, // Color for hour display
|
||||||
green, // Color for minute display
|
green, // Color for minute display
|
||||||
blue}, // Color for second display
|
blue}, // Color for second display
|
||||||
@ -48,6 +48,9 @@ const CRGB colorSchemes[colorSchemeCount][4] = {
|
|||||||
const bool useEnhancedRenderer = true;
|
const bool useEnhancedRenderer = true;
|
||||||
const bool showSecondHand = true;
|
const bool showSecondHand = true;
|
||||||
const bool twelveHour = true;
|
const bool twelveHour = true;
|
||||||
|
const int hourGlowWidth = 4; // Pixels in each direction
|
||||||
|
const int minuteGlowWidth = 2; // Pixels in each direction
|
||||||
|
const int secondGlowWidth = 1; // Pixels in each direction
|
||||||
const int buttonClickRepeatDelayMs = 1500;
|
const int buttonClickRepeatDelayMs = 1500;
|
||||||
const int buttonLongPressDelayMs = 300;
|
const int buttonLongPressDelayMs = 300;
|
||||||
|
|
||||||
@ -60,8 +63,7 @@ typedef enum {
|
|||||||
ClockModeRingClock,
|
ClockModeRingClock,
|
||||||
ClockModeDotClock,
|
ClockModeDotClock,
|
||||||
ClockModeDotClockTrail,
|
ClockModeDotClockTrail,
|
||||||
ClockModeDotClockColorChange,
|
ClockModeDotClockGlow,
|
||||||
ClockModeGlowClock,
|
|
||||||
ClockModeCount
|
ClockModeCount
|
||||||
} ClockMode;
|
} ClockMode;
|
||||||
|
|
||||||
@ -75,25 +77,6 @@ const int runLoopIntervalMs = 30;
|
|||||||
const uint16_t eepromAddrColorScheme = 0;
|
const uint16_t eepromAddrColorScheme = 0;
|
||||||
const uint16_t eepromAddrClockMode = 1;
|
const uint16_t eepromAddrClockMode = 1;
|
||||||
|
|
||||||
// Gamma correction values
|
|
||||||
const uint8_t PROGMEM gamma[] = {
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
|
|
||||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
|
|
||||||
2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5,
|
|
||||||
5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10,
|
|
||||||
10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16,
|
|
||||||
17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25,
|
|
||||||
25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36,
|
|
||||||
37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50,
|
|
||||||
51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68,
|
|
||||||
69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89,
|
|
||||||
90, 92, 93, 95, 96, 98, 99,101,102,104,105,107,109,110,112,114,
|
|
||||||
115,117,119,120,122,124,126,127,129,131,133,135,137,138,140,142,
|
|
||||||
144,146,148,150,152,154,156,158,160,162,164,167,169,171,173,175,
|
|
||||||
177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213,
|
|
||||||
215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 };
|
|
||||||
|
|
||||||
// LED blend modes
|
// LED blend modes
|
||||||
typedef enum {
|
typedef enum {
|
||||||
BlendModeOver,
|
BlendModeOver,
|
||||||
|
@ -18,13 +18,13 @@ RTC_DS1307 rtc;
|
|||||||
|
|
||||||
// Globals to keep track of state
|
// Globals to keep track of state
|
||||||
int clockMode, colorScheme;
|
int clockMode, colorScheme;
|
||||||
int lastLoopTime = 0;
|
uint32_t lastLoopTime = 0;
|
||||||
int lastButtonClickTime = 0;
|
uint32_t lastButtonClickTime = 0;
|
||||||
int lastDebugMessageTime = 0;
|
uint32_t lastDebugMessageTime = 0;
|
||||||
uint8_t currentBrightness;
|
uint8_t currentBrightness;
|
||||||
uint8_t previousBrightness[16];
|
uint8_t previousBrightness[16];
|
||||||
int lastSecondsValue = 0;
|
int lastSecondsValue = 0;
|
||||||
int lastMillisecondsSetTime = 0;
|
uint32_t lastMillisecondsSetTime = 0;
|
||||||
int milliseconds;
|
int milliseconds;
|
||||||
DateTime now;
|
DateTime now;
|
||||||
|
|
||||||
@ -57,21 +57,22 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
int currentTime = millis();
|
uint32_t currentTime = millis();
|
||||||
if (currentTime - lastLoopTime > runLoopIntervalMs) {
|
if (currentTime - lastLoopTime > runLoopIntervalMs) {
|
||||||
lastLoopTime = currentTime;
|
lastLoopTime = currentTime;
|
||||||
// Handle button
|
// Handle button
|
||||||
if (digitalRead(pinButton) == LOW && currentTime - lastButtonClickTime > buttonClickRepeatDelayMs) {
|
if (digitalRead(pinButton) == LOW && currentTime - lastButtonClickTime > buttonClickRepeatDelayMs) {
|
||||||
delay(buttonLongPressDelayMs);
|
delay(buttonLongPressDelayMs);
|
||||||
|
// Long press: clock mode, short press: color scheme
|
||||||
if (digitalRead(pinButton) == LOW) {
|
if (digitalRead(pinButton) == LOW) {
|
||||||
lastButtonClickTime = currentTime;
|
lastButtonClickTime = currentTime;
|
||||||
colorScheme ++;
|
colorScheme ++;
|
||||||
if (colorScheme >= colorSchemeCount + 2) colorScheme = 0; // 2 special color schemes
|
if (colorScheme >= colorSchemeCount + 2) colorScheme = 0; // 2 special color schemes
|
||||||
EEPROM.write(0, colorScheme);
|
EEPROM.write(eepromAddrColorScheme, colorScheme);
|
||||||
} else {
|
} else {
|
||||||
clockMode ++;
|
clockMode ++;
|
||||||
if (clockMode >= ClockModeCount) clockMode = 0;
|
if (clockMode >= ClockModeCount) clockMode = 0;
|
||||||
EEPROM.write(1, clockMode);
|
EEPROM.write(eepromAddrClockMode, clockMode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,11 +122,8 @@ void showClock() {
|
|||||||
case ClockModeDotClockTrail:
|
case ClockModeDotClockTrail:
|
||||||
drawDotClockTrail();
|
drawDotClockTrail();
|
||||||
break;
|
break;
|
||||||
case ClockModeDotClockColorChange:
|
case ClockModeDotClockGlow:
|
||||||
drawDotClockColorChange();
|
drawDotClockGlow();
|
||||||
break;
|
|
||||||
case ClockModeGlowClock:
|
|
||||||
drawGlowClock();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -159,7 +157,7 @@ void printDebugMessage() {
|
|||||||
void drawRingClock() {
|
void drawRingClock() {
|
||||||
int h = hourPosition();
|
int h = hourPosition();
|
||||||
int m = minutePosition();
|
int m = minutePosition();
|
||||||
float s = floatSecondPosition();
|
float s = secondPosition();
|
||||||
|
|
||||||
if (m > h) {
|
if (m > h) {
|
||||||
for (int i = 0; i < m; i++) setLed(i, minuteColor(), BlendModeOver, 1.0);
|
for (int i = 0; i < m; i++) setLed(i, minuteColor(), BlendModeOver, 1.0);
|
||||||
@ -176,9 +174,9 @@ void drawRingClock() {
|
|||||||
|
|
||||||
// Show a more traditional dot clock
|
// Show a more traditional dot clock
|
||||||
void drawDotClock() {
|
void drawDotClock() {
|
||||||
float h = floatHourPosition();
|
float h = hourPosition();
|
||||||
float m = floatMinutePosition();
|
float m = minutePosition();
|
||||||
float s = floatSecondPosition();
|
float s = secondPosition();
|
||||||
|
|
||||||
for (float i = h - 1.0; i < h + 2.0; i++) setLed(i, hourColor(), BlendModeAlpha, 1.0);
|
for (float i = h - 1.0; i < h + 2.0; i++) setLed(i, hourColor(), BlendModeAlpha, 1.0);
|
||||||
setLed(m, minuteColor(), BlendModeAlpha, 1.0);
|
setLed(m, minuteColor(), BlendModeAlpha, 1.0);
|
||||||
@ -187,11 +185,11 @@ void drawDotClock() {
|
|||||||
FastLED.show();
|
FastLED.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show a dot clock with longer hands
|
// Show a dot clock where the hands have a glowing trail behing them
|
||||||
void drawDotClockTrail() {
|
void drawDotClockTrail() {
|
||||||
float h = floatHourPosition();
|
float h = hourPosition();
|
||||||
float m = floatMinutePosition();
|
float m = minutePosition();
|
||||||
float s = floatSecondPosition();
|
float s = secondPosition();
|
||||||
|
|
||||||
for (float i = h - 1.0; i < h + 2.0; i++) setLed(i, hourColor(), BlendModeAdd, 1.0);
|
for (float i = h - 1.0; i < h + 2.0; i++) setLed(i, hourColor(), BlendModeAdd, 1.0);
|
||||||
for (float i = -4.0; i < 1.0; i++) setLed(m + i, minuteColor(), BlendModeAdd, 1.0 + (i / 5.0));
|
for (float i = -4.0; i < 1.0; i++) setLed(m + i, minuteColor(), BlendModeAdd, 1.0 + (i / 5.0));
|
||||||
@ -200,29 +198,24 @@ void drawDotClockTrail() {
|
|||||||
FastLED.show();
|
FastLED.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show a dot clock with hands that change color based on their position
|
// Show a dot clock where the hands glow outwards from their position
|
||||||
void drawDotClockColorChange() {
|
void drawDotClockGlow() {
|
||||||
float h = floatHourPosition();
|
float h = hourPosition();
|
||||||
float m = floatMinutePosition();
|
float m = minutePosition();
|
||||||
float s = floatSecondPosition();
|
float s = secondPosition();
|
||||||
|
|
||||||
CRGB newHourColor = CHSV(map(now.hour(), 0, 24, 0, 255), 255, 255);
|
for (float i = h - hourGlowWidth; i <= h + hourGlowWidth; i++) {
|
||||||
CRGB newMinuteColor = CHSV(map(now.minute(), 0, 59, 0, 255), 255, 255);
|
setLed(i, hourColor(), BlendModeAdd, mapFloat(fabs(h - i), 0.0, hourGlowWidth, 1.0, 0.1));
|
||||||
CRGB newSecondColor = CHSV(map(now.second(), 0, 59, 0, 255), 255, 255);
|
|
||||||
|
|
||||||
for (float i = h - 1.0; i < h + 2.0; i++) setLed(i, newHourColor, BlendModeAdd, 1.0);
|
|
||||||
setLed(m, newMinuteColor, BlendModeAdd, 1.0);
|
|
||||||
if (showSecondHand) setLed(s, newSecondColor, BlendModeAdd, 1.0);
|
|
||||||
|
|
||||||
FastLED.show();
|
|
||||||
}
|
}
|
||||||
|
for (float i = m - minuteGlowWidth; i <= m + minuteGlowWidth; i++) {
|
||||||
// Show a dot clock where the hands overlap with additive blending
|
setLed(i, minuteColor(), BlendModeAdd, mapFloat(fabs(m - i), 0.0, minuteGlowWidth, 1.0, 0.1));
|
||||||
void drawGlowClock() {
|
}
|
||||||
int h = hourPosition();
|
if (showSecondHand) {
|
||||||
int m = minutePosition();
|
for (float i = s - secondGlowWidth; i <= s + secondGlowWidth; i++) {
|
||||||
int s = secondPosition();
|
setLed(i, secondColor(), BlendModeAdd, mapFloat(fabs(s - i), 0.0, secondGlowWidth, 1.0, 0.1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
for (int i = -6; i < ledRingSize + 6; i++) {
|
for (int i = -6; i < ledRingSize + 6; i++) {
|
||||||
int j;
|
int j;
|
||||||
for (j = 0; j <= 4; j++) {
|
for (j = 0; j <= 4; j++) {
|
||||||
@ -236,7 +229,7 @@ void drawGlowClock() {
|
|||||||
if (s + j == i || s - j == i) blendAdd(wrap(i), CRGB(0, 0, 255), 1 - mapFloat(j, 0.0, 1.0, 0.1, 0.65));
|
if (s + j == i || s - j == i) blendAdd(wrap(i), CRGB(0, 0, 255), 1 - mapFloat(j, 0.0, 1.0, 0.1, 0.65));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
FastLED.show();
|
FastLED.show();
|
||||||
}
|
}
|
||||||
@ -247,28 +240,7 @@ float floatHour() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get positions mapped to ring size
|
// Get positions mapped to ring size
|
||||||
int hourPosition() {
|
float hourPosition() {
|
||||||
if (twelveHour) {
|
|
||||||
int hour;
|
|
||||||
if (now.hour() > 12) hour = (now.hour() - 12) * (ledRingSize / 12);
|
|
||||||
else hour = now.hour() * (ledRingSize / 12);
|
|
||||||
return hour + map(now.minute(), 0, 59, 0, (ledRingSize / 12) - 1);
|
|
||||||
} else {
|
|
||||||
int hour = now.hour() * (ledRingSize / 24);
|
|
||||||
return hour + map(now.minute(), 0, 59, 0, (ledRingSize / 24) - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int minutePosition() {
|
|
||||||
return map(now.minute(), 0, 59, 0, ledRingSize - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int secondPosition() {
|
|
||||||
return map(now.second(), 0, 59, 0, ledRingSize - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get positions as a float mapped to ring size
|
|
||||||
float floatHourPosition() {
|
|
||||||
if (twelveHour) {
|
if (twelveHour) {
|
||||||
int hour;
|
int hour;
|
||||||
if (now.hour() > 12) hour = (now.hour() - 12) * (ledRingSize / 12);
|
if (now.hour() > 12) hour = (now.hour() - 12) * (ledRingSize / 12);
|
||||||
@ -280,11 +252,11 @@ float floatHourPosition() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float floatMinutePosition() {
|
float minutePosition() {
|
||||||
return mapFloat((float)now.minute() + ((1.0 / 60.0) * (float)now.second()), 0.0, 59.0, 0.0, (float)ledRingSize);
|
return mapFloat((float)now.minute() + ((1.0 / 60.0) * (float)now.second()), 0.0, 59.0, 0.0, (float)ledRingSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
float floatSecondPosition() {
|
float secondPosition() {
|
||||||
return mapFloat(now.second() + (0.001 * milliseconds), 0.0, 60.0, 0.0, (float)ledRingSize);
|
return mapFloat(now.second() + (0.001 * milliseconds), 0.0, 60.0, 0.0, (float)ledRingSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,7 +264,7 @@ float floatSecondPosition() {
|
|||||||
CRGB hourColor() {
|
CRGB hourColor() {
|
||||||
if (colorScheme < colorSchemeCount) return colorSchemes[colorScheme][0];
|
if (colorScheme < colorSchemeCount) return colorSchemes[colorScheme][0];
|
||||||
else if (colorScheme == colorSchemeCount + 0) {
|
else if (colorScheme == colorSchemeCount + 0) {
|
||||||
return white;
|
return CHSV(map(now.hour(), 0, 24, 0, 255), 255, 255);
|
||||||
} else if (colorScheme == colorSchemeCount + 1) {
|
} else if (colorScheme == colorSchemeCount + 1) {
|
||||||
return CHSV((uint8_t)mapFloat(fmod(20.0 - floatHour(), 24.0), 0.0, 24.0, 0.0, 255.0), 255, 255);
|
return CHSV((uint8_t)mapFloat(fmod(20.0 - floatHour(), 24.0), 0.0, 24.0, 0.0, 255.0), 255, 255);
|
||||||
}
|
}
|
||||||
@ -301,7 +273,7 @@ CRGB hourColor() {
|
|||||||
CRGB minuteColor() {
|
CRGB minuteColor() {
|
||||||
if (colorScheme < colorSchemeCount) return colorSchemes[colorScheme][1];
|
if (colorScheme < colorSchemeCount) return colorSchemes[colorScheme][1];
|
||||||
else if (colorScheme == colorSchemeCount + 0) {
|
else if (colorScheme == colorSchemeCount + 0) {
|
||||||
return white;
|
return CHSV(map(now.minute(), 0, 59, 0, 255), 255, 255);
|
||||||
} else if (colorScheme == colorSchemeCount + 1) {
|
} else if (colorScheme == colorSchemeCount + 1) {
|
||||||
return CHSV((uint8_t)mapFloat(fmod(20.0 - floatHour(), 24.0), 0.0, 24.0, 0.0, 255.0), 255, 255);
|
return CHSV((uint8_t)mapFloat(fmod(20.0 - floatHour(), 24.0), 0.0, 24.0, 0.0, 255.0), 255, 255);
|
||||||
}
|
}
|
||||||
@ -310,7 +282,7 @@ CRGB minuteColor() {
|
|||||||
CRGB secondColor() {
|
CRGB secondColor() {
|
||||||
if (colorScheme < colorSchemeCount) return colorSchemes[colorScheme][2];
|
if (colorScheme < colorSchemeCount) return colorSchemes[colorScheme][2];
|
||||||
else if (colorScheme == colorSchemeCount + 0) {
|
else if (colorScheme == colorSchemeCount + 0) {
|
||||||
return white;
|
return CHSV(map(now.second(), 0, 59, 0, 255), 255, 255);
|
||||||
} else if (colorScheme == colorSchemeCount + 1) {
|
} else if (colorScheme == colorSchemeCount + 1) {
|
||||||
return CHSV((uint8_t)mapFloat(fmod(20.0 - floatHour(), 24.0), 0.0, 24.0, 0.0, 255.0), 255, 255);
|
return CHSV((uint8_t)mapFloat(fmod(20.0 - floatHour(), 24.0), 0.0, 24.0, 0.0, 255.0), 255, 255);
|
||||||
}
|
}
|
||||||
@ -318,12 +290,7 @@ CRGB secondColor() {
|
|||||||
|
|
||||||
// Clear the LED ring
|
// Clear the LED ring
|
||||||
void clearLeds() {
|
void clearLeds() {
|
||||||
for (int i = 0; i < ledRingSize; i++) {
|
for (int i = 0; i < ledRingSize; i++) leds[i] = CRGB(0, 0, 0);
|
||||||
leds[i] = CRGB(0, 0, 0);
|
|
||||||
//leds[i].r = max(leds[i].r - 1, 0);
|
|
||||||
//leds[i].g = max(leds[i].g - 2, 0);
|
|
||||||
//leds[i].b = max(leds[i].b - 3, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set LED(s) at a position with enhanced rendering
|
// Set LED(s) at a position with enhanced rendering
|
||||||
|
Loading…
Reference in New Issue
Block a user