moving colored clock modes into special color schemes

This commit is contained in:
jackw01 2018-09-08 23:02:50 -07:00
parent 4d35218695
commit 45a7ffb513
2 changed files with 88 additions and 70 deletions

View File

@ -19,15 +19,15 @@ const uint8_t pinBrightness = 0;
const int ledRingSize = 24; const int ledRingSize = 24;
// Default colors - tweaked to look right on WS2812Bs // Default colors - tweaked to look right on WS2812Bs
CRGB red = CRGB(255, 0, 0); const CRGB red = CRGB(255, 0, 0);
CRGB orange = CRGB(255, 78, 0); const CRGB orange = CRGB(255, 78, 0);
CRGB yellow = CRGB(255, 237, 0); const CRGB yellow = CRGB(255, 237, 0);
CRGB green = CRGB(0, 255, 23); const CRGB green = CRGB(0, 255, 23);
CRGB cyan = CRGB(0, 247, 255); const CRGB cyan = CRGB(0, 247, 255);
CRGB blue = CRGB(0, 21, 255); const CRGB blue = CRGB(0, 21, 255);
CRGB magenta = CRGB(190, 0, 255); const CRGB magenta = CRGB(190, 0, 255);
CRGB white = CRGB(255, 255, 255); const CRGB white = CRGB(255, 255, 255);
CRGB off = CRGB(0, 0, 0); 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)
@ -46,10 +46,10 @@ const CRGB colorSchemes[colorSchemeCount][4] = {
// Clock settings // Clock settings
const bool useEnhancedRenderer = true; const bool useEnhancedRenderer = true;
const int buttonClickRepeatDelayMs = 1500;
const int buttonLongPressDelayMs = 300;
const bool showSecondHand = true; const bool showSecondHand = true;
const bool twelveHour = true; const bool twelveHour = true;
const int buttonClickRepeatDelayMs = 1500;
const int buttonLongPressDelayMs = 300;
// Serial // Serial
const long serialPortBaudRate = 115200; const long serialPortBaudRate = 115200;
@ -59,8 +59,8 @@ const int debugMessageIntervalMs = 2000;
typedef enum { typedef enum {
ClockModeRingClock, ClockModeRingClock,
ClockModeDotClock, ClockModeDotClock,
ClockModeDotClockTrail,
ClockModeDotClockColorChange, ClockModeDotClockColorChange,
ClockModeDotClockTimeColor,
ClockModeGlowClock, ClockModeGlowClock,
ClockModeCount ClockModeCount
} ClockMode; } ClockMode;

View File

@ -66,7 +66,7 @@ void loop() {
if (digitalRead(pinButton) == LOW) { if (digitalRead(pinButton) == LOW) {
lastButtonClickTime = currentTime; lastButtonClickTime = currentTime;
colorScheme ++; colorScheme ++;
if (colorScheme >= colorSchemeCount) colorScheme = 0; if (colorScheme >= colorSchemeCount + 2) colorScheme = 0; // 2 special color schemes
EEPROM.write(0, colorScheme); EEPROM.write(0, colorScheme);
} else { } else {
clockMode ++; clockMode ++;
@ -113,19 +113,19 @@ void loop() {
void showClock() { void showClock() {
switch (clockMode) { switch (clockMode) {
case ClockModeRingClock: case ClockModeRingClock:
ringClock(); drawRingClock();
break; break;
case ClockModeDotClock: case ClockModeDotClock:
dotClock(); drawDotClock();
break;
case ClockModeDotClockTrail:
drawDotClockTrail();
break; break;
case ClockModeDotClockColorChange: case ClockModeDotClockColorChange:
rainbowDotClock(); drawDotClockColorChange();
break;
case ClockModeDotClockTimeColor:
timeColorClock();
break; break;
case ClockModeGlowClock: case ClockModeGlowClock:
glowClock(); drawGlowClock();
break; break;
} }
} }
@ -156,72 +156,69 @@ void printDebugMessage() {
} }
// Show a ring clock // Show a ring clock
void ringClock() { void drawRingClock() {
int h = hourPosition(); int h = hourPosition();
int m = minutePosition(); int m = minutePosition();
float s = floatSecondPosition(); float s = floatSecondPosition();
if (m > h) { if (m > h) {
for (int i = 0; i < m; i++) setLed(i, minuteColor(), BlendModeOver); for (int i = 0; i < m; i++) setLed(i, minuteColor(), BlendModeOver, 1.0);
for (int i = 0; i < h; i++) setLed(i, hourColor(), BlendModeOver); for (int i = 0; i < h; i++) setLed(i, hourColor(), BlendModeOver, 1.0);
} else { } else {
for (int i = 0; i < h; i++) setLed(i, hourColor(), BlendModeOver); for (int i = 0; i < h; i++) setLed(i, hourColor(), BlendModeOver, 1.0);
for (int i = 0; i < m; i++) setLed(i, minuteColor(), BlendModeOver); for (int i = 0; i < m; i++) setLed(i, minuteColor(), BlendModeOver, 1.0);
} }
if (showSecondHand) setLed(s, secondColor(), BlendModeAlpha); if (showSecondHand) setLed(s, secondColor(), BlendModeAlpha, 1.0);
FastLED.show(); FastLED.show();
} }
// Show a more traditional dot clock // Show a more traditional dot clock
void dotClock() { void drawDotClock() {
float h = floatHourPosition(); float h = floatHourPosition();
float m = floatMinutePosition(); float m = floatMinutePosition();
float s = floatSecondPosition(); float s = floatSecondPosition();
for (float i = h - 1; i < h + 2; i++) setLed(i, hourColor(), BlendModeAdd); for (float i = h - 1.0; i < h + 2.0; i++) setLed(i, hourColor(), BlendModeAlpha, 1.0);
setLed(m, minuteColor(), BlendModeAdd); setLed(m, minuteColor(), BlendModeAlpha, 1.0);
if (showSecondHand) setLed(s, secondColor(), BlendModeAdd); if (showSecondHand) setLed(s, secondColor(), BlendModeAlpha, 1.0);
FastLED.show();
}
// Show a dot clock with longer hands
void drawDotClockTrail() {
float h = floatHourPosition();
float m = floatMinutePosition();
float s = floatSecondPosition();
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));
if (showSecondHand) for (float i = -3.0; i < 1.0; i++) setLed(s + i, secondColor(), BlendModeAdd, 1.0 + (i / 4.0));
FastLED.show(); FastLED.show();
} }
// Show a dot clock with hands that change color based on their position // Show a dot clock with hands that change color based on their position
void rainbowDotClock() { void drawDotClockColorChange() {
int h = hourPosition(); float h = floatHourPosition();
int m = minutePosition(); float m = floatMinutePosition();
int s = secondPosition(); float s = floatSecondPosition();
CRGB newHourColor = CHSV(map(now.hour(), 0, 24, 0, 255), 255, 255); CRGB newHourColor = CHSV(map(now.hour(), 0, 24, 0, 255), 255, 255);
CRGB newMinuteColor = CHSV(map(now.minute(), 0, 59, 0, 255), 255, 255); CRGB newMinuteColor = CHSV(map(now.minute(), 0, 59, 0, 255), 255, 255);
CRGB newSecondColor = CHSV(map(now.second(), 0, 59, 0, 255), 255, 255); CRGB newSecondColor = CHSV(map(now.second(), 0, 59, 0, 255), 255, 255);
for (int i = h - 1; i < h + 2; i++) leds[wrap(i)] = newHourColor; for (float i = h - 1.0; i < h + 2.0; i++) setLed(i, newHourColor, BlendModeAdd, 1.0);
leds[m] = newMinuteColor; setLed(m, newMinuteColor, BlendModeAdd, 1.0);
if (showSecondHand) leds[s] = newSecondColor; if (showSecondHand) setLed(s, newSecondColor, BlendModeAdd, 1.0);
FastLED.show();
}
// Show a dot clock where the color is based on the time
void timeColorClock() {
int h = hourPosition();
int m = minutePosition();
int s = secondPosition();
float fHour = floatHour();
CRGB pixelColor = CHSV((uint8_t)mapFloat(fmod(20.0 - fHour, 24.0), 0.0, 24.0, 0.0, 255.0), 255, 255);
for (int i = h - 1; i < h + 2; i++) leds[wrap(i)] = pixelColor;
leds[m] = pixelColor;
if (showSecondHand) leds[s] = pixelColor;
FastLED.show(); FastLED.show();
} }
// Show a dot clock where the hands overlap with additive blending // Show a dot clock where the hands overlap with additive blending
void glowClock() { void drawGlowClock() {
int h = hourPosition(); int h = hourPosition();
int m = minutePosition(); int m = minutePosition();
int s = secondPosition(); int s = secondPosition();
@ -244,6 +241,11 @@ void glowClock() {
FastLED.show(); FastLED.show();
} }
// Get floating point hour representation
float floatHour() {
return (float)now.hour() + mapFloat(now.minute() + mapFloat(now.second(), 0.0, 59.0, 0.0, 1.0), 0.0, 59.0, 0.0, 1.0);
}
// Get positions mapped to ring size // Get positions mapped to ring size
int hourPosition() { int hourPosition() {
if (twelveHour) { if (twelveHour) {
@ -265,10 +267,6 @@ int secondPosition() {
return map(now.second(), 0, 59, 0, ledRingSize - 1); return map(now.second(), 0, 59, 0, ledRingSize - 1);
} }
float floatHour() {
return (float)now.hour() + mapFloat(now.minute() + mapFloat(now.second(), 0.0, 59.0, 0.0, 1.0), 0.0, 59.0, 0.0, 1.0);
}
// Get positions as a float mapped to ring size // Get positions as a float mapped to ring size
float floatHourPosition() { float floatHourPosition() {
if (twelveHour) { if (twelveHour) {
@ -283,7 +281,7 @@ float floatHourPosition() {
} }
float floatMinutePosition() { float floatMinutePosition() {
return mapFloat(now.minute() + ((1 / 60) * 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 floatSecondPosition() {
@ -292,38 +290,58 @@ float floatSecondPosition() {
// Get colors // Get colors
CRGB hourColor() { CRGB hourColor() {
return colorSchemes[colorScheme][0]; if (colorScheme < colorSchemeCount) return colorSchemes[colorScheme][0];
else if (colorScheme == colorSchemeCount + 0) {
return white;
} 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);
}
} }
CRGB minuteColor() { CRGB minuteColor() {
return colorSchemes[colorScheme][1]; if (colorScheme < colorSchemeCount) return colorSchemes[colorScheme][1];
else if (colorScheme == colorSchemeCount + 0) {
return white;
} 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);
}
} }
CRGB secondColor() { CRGB secondColor() {
return colorSchemes[colorScheme][2]; if (colorScheme < colorSchemeCount) return colorSchemes[colorScheme][2];
else if (colorScheme == colorSchemeCount + 0) {
return white;
} 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);
}
} }
// Clear the LED ring // Clear the LED ring
void clearLeds() { void clearLeds() {
for (int i = 0; i < ledRingSize; i++) leds[i] = CRGB(0, 0, 0); for (int i = 0; i < ledRingSize; i++) {
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
void setLed(float position, CRGB color, BlendMode blendMode) { void setLed(float position, CRGB color, BlendMode blendMode, float factor) {
if (useEnhancedRenderer) { if (useEnhancedRenderer) {
int low = floor(position); int low = floor(position);
int high = ceil(position); int high = ceil(position);
float lowFactor = ((float)high - position); float lowFactor = ((float)high - position);
float highFactor = (position - (float)low); float highFactor = (position - (float)low);
if (blendMode == BlendModeAdd) { if (blendMode == BlendModeAdd) {
blendAdd(wrap(low), color, lowFactor); blendAdd(wrap(low), color, lowFactor * factor);
blendAdd(wrap(high), color, highFactor); blendAdd(wrap(high), color, highFactor * factor);
} else if (blendMode == BlendModeAlpha) { } else if (blendMode == BlendModeAlpha) {
blendAlpha(wrap(low), color, lowFactor); blendAlpha(wrap(low), color, lowFactor * factor);
blendAlpha(wrap(high), color, highFactor); blendAlpha(wrap(high), color, highFactor * factor);
} else if (blendMode == BlendModeOver) { } else if (blendMode == BlendModeOver) {
blendOver(wrap(low), color, lowFactor); blendOver(wrap(low), color, lowFactor * factor);
blendOver(wrap(high), color, highFactor); blendOver(wrap(high), color, highFactor * factor);
} }
} else { } else {
leds[wrap((int)position)] = color; leds[wrap((int)position)] = color;