diff --git a/config.h b/config.h new file mode 100644 index 0000000..eceff36 --- /dev/null +++ b/config.h @@ -0,0 +1,96 @@ +// +// WS2812 LED Analog Clock Firmware +// Copyright (c) 2016-2018 jackw01 +// This code is distrubuted under the MIT License, see LICENSE for details +// + +#ifndef CONFIG_H +#define CONFIG_H + +#include +#include + +// IO Pin Assignments +const uint8_t pinLeds = 3; +const uint8_t pinButton = 4; +const uint8_t pinBrightness = 0; + +// Number of LEDs in ring +const int ledRingSize = 24; + +// Default colors - tweaked to look right on WS2812Bs +CRGB red = CRGB(255, 0, 0); +CRGB orange = CRGB(255, 78, 0); +CRGB yellow = CRGB(255, 237, 0); +CRGB green = CRGB(0, 255, 23); +CRGB cyan = CRGB(0, 247, 255); +CRGB blue = CRGB(0, 21, 255); +CRGB magenta = CRGB(190, 0, 255); +CRGB white = CRGB(255, 255, 255); +CRGB off = CRGB(0, 0, 0); + +// Default clock face colors +// red, orange, yellow, green, cyan, blue, magenta, and white are acceptable, along with CRGB(r, g, b) +const int colorSchemeCount = 7; +const CRGB colorSchemes[colorSchemeCount][4] = { + {red, // Color for hour display + green, // Color for minute display + blue}, // Color for second display + { CRGB(255, 255, 255), CRGB(255, 255, 255), CRGB( 0, 130, 255) }, + { CRGB(255, 255, 255), CRGB(255, 255, 255), CRGB(255, 25, 0) }, + { CRGB( 64, 0, 128), CRGB(255, 72, 0), CRGB(255, 164, 0) }, + { CRGB(255, 25, 0), CRGB(255, 84, 0), CRGB(255, 224, 0) }, + { CRGB( 0, 0, 255), CRGB( 0, 84, 255), CRGB( 0, 255, 255) }, + { CRGB(255, 0, 96), CRGB(255, 84, 0), CRGB( 0, 255, 164) } +}; + +// Clock settings +const int buttonClickRepeatDelayMs = 1500; +const int buttonLongPressDelayMs = 300; +const bool showSecondHand = true; +const bool twelveHour = true; + +// Serial +const int serialPortBaudRate = 115200; +const int debugMessageIntervalMs = 5000; + +// Clock modes +typedef enum { + ClockModeRingClock, + ClockModeDotClock, + ClockModeDotClockColorChange, + ClockModeDotClockTimeColor, + ClockModeGlowClock, + ClockModeCount +} ClockMode; + +// Brightness +const uint8_t minBrightness = 4; + +// Run loop +const int runLoopIntervalMs = 30; + +// EEPROM Addresses +const uint16_t eepromAddrColorScheme = 0; +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 }; + +#endif diff --git a/led-ring-clock.ino b/led-ring-clock.ino index 38fa939..e9f601d 100644 --- a/led-ring-clock.ino +++ b/led-ring-clock.ino @@ -1,208 +1,122 @@ // -// Copyright (c) 2015-2017 jackw01 +// Copyright (c) 2016-2018 jackw01 // This code is distrubuted under the MIT License, see LICENSE for details // +#include #include #include #include -#include "RTClib.h" +#include -// -// Adjust these variables to taste -// - -// Pin Assignments -const int pinLeds = 3; -const int pinButton = 4; -const int pinBrightness = 0; - -const int ledRingSize = 24; // Number of LEDs in ring - -// Default colors -CRGB red = CRGB(255, 0, 0); -CRGB orange = CRGB(255, 78, 0); -CRGB yellow = CRGB(255, 237, 0); -CRGB green = CRGB(0, 255, 23); -CRGB cyan = CRGB(0, 247, 255); -CRGB blue = CRGB(0, 21, 255); -CRGB magenta = CRGB(190, 0, 255); -CRGB white = CRGB(255, 255, 255); -CRGB off = CRGB(0, 0, 0); - -// Clock face colors -// red, orange, yellow, green, cyan, blue, magenta, and white are acceptable, along with CRGB(r, g, b) -const int colorSchemeMax = 6; -const CRGB colorSchemes[colorSchemeMax + 1][4] = {{off, // Color when only one is needed (deprecated) - red, // Color for hour display - green, // Color for minute display - blue}, // Color for second display - {CRGB(0, 0, 0), CRGB(255, 255, 255), CRGB(255, 255, 255), CRGB(0, 130, 255)}, - {CRGB(0, 0, 0), CRGB(255, 255, 255), CRGB(255, 255, 255), CRGB(255, 25, 0)}, - {CRGB(0, 0, 0), CRGB(64, 0, 128), CRGB(255, 72, 0), CRGB(255, 164, 0)}, - {CRGB(0, 0, 0), CRGB(255, 25, 0), CRGB(255, 84, 0), CRGB(255, 224, 0)}, - {CRGB(0, 0, 0), CRGB(0, 0, 255), CRGB(0, 84, 255), CRGB(0, 255, 255)}, - {CRGB(0, 0, 0), CRGB(255, 0, 96), CRGB(255, 84, 0), CRGB(0, 255, 164)}}; - -const int gradientMax = 1; -const CRGB gradients[gradientMax + 1][6] = {{CRGB(72, 0, 96), CRGB(255, 72, 0), CRGB(255, 164, 0), CRGB(255, 224, 0), CRGB(0, 255, 164), CRGB(0, 208, 255)}, - {CRGB(72, 0, 96), CRGB(255, 72, 0), CRGB(255, 164, 0), CRGB(255, 224, 0), CRGB(0, 255, 164), CRGB(0, 208, 255)}}; - -// Setup ends -// Code starts here - -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 }; +#include "config.h" CRGB leds[ledRingSize]; RTC_DS1307 rtc; -int clockMode, colorScheme, gradient; -int clockModeMax = 4; -int buttonState = 0; -const int minBrightness = 4; -int currentBrightness; -uint8_t previousBrightness[16]; -int counter = 0; -int timer = 0; - -const int debugMessageInterval = 1000; +// Globals to keep track of state +int clockMode, colorScheme; +int lastLoopTime = 0; +int lastButtonClickTime = 0; int lastDebugMessageTime = 0; - -CRGB handColor, hourColor, minuteColor, secondColor; +uint8_t currentBrightness; +uint8_t previousBrightness[16]; +DateTime now; void setup() { - - Serial.begin(57600); + // Begin serial port + Serial.begin(serialPortBaudRate); // Init FastLED FastLED.addLeds(leds, ledRingSize); FastLED.setTemperature(Halogen); FastLED.show(); + // Connect to the RTC Wire.begin(); rtc.begin(); + // Set button pin pinMode(pinButton, INPUT); - colorScheme = EEPROM.read(0); - clockMode = EEPROM.read(1); - gradient = 0; + // Read saved config from EEPROM + colorScheme = EEPROM.read(eepromAddrColorScheme); + clockMode = EEPROM.read(eepromAddrClockMode); - handColor = colorSchemes[colorScheme][0]; - hourColor = colorSchemes[colorScheme][1]; - minuteColor = colorSchemes[colorScheme][2]; - secondColor = colorSchemes[colorScheme][3]; - - // Serial debug - Serial.println("WS2812B LED Ring Clock by jackw01"); - - // Light mode + // If button is pressed at startup, light all LEDs if (digitalRead(pinButton) == LOW) { for (int i = 0; i < ledRingSize; i++) leds[i] = white; FastLED.show(); delay(60000); } - - // Test animation - for (int i = 0; i < ledRingSize; i++) { - leds[i] = white; - FastLED.show(); - delay(40); - } - for (int i = 0; i < ledRingSize; i++) { - leds[i] = off; - FastLED.show(); - delay(40); - } } void loop() { + int currentTime = millis(); + if (currentTime - lastLoopTime > runLoopIntervalMs) { + lastLoopTime = millis(); + // Handle button + if (digitalRead(pinButton) == LOW && currentTime - lastButtonClickTime > buttonClickRepeatDelayMs) { + delay(buttonLongPressDelayMs); + if (digitalRead(pinButton) == LOW) { + lastButtonClickTime = currentTime; + colorScheme ++; + if (colorScheme >= colorSchemeCount) colorScheme = 0; + EEPROM.write(0, colorScheme); + } else { + clockMode ++; + if (clockMode >= ClockModeCount) clockMode = 0; + EEPROM.write(1, clockMode); + } + } - if (digitalRead(pinButton) == LOW && counter >= 14) { + // Print debug message + if (currentTime > lastDebugMessageTime + debugMessageIntervalMs) { + lastDebugMessageTime = currentTime; + printDebugMessage(); + } - counter = 0; + // Update brightness - do a moving average to smooth out noisy potentiometers + int sum = 0; + for (uint8_t i = 15; i > 0; i--) { + previousBrightness[i] = previousBrightness[i - 1]; + sum += previousBrightness[i]; + } + previousBrightness[0] = map(analogRead(pinBrightness), 0, 1023, minBrightness, 255); + sum += previousBrightness[0]; + currentBrightness = sum / 16; + FastLED.setBrightness(currentBrightness); - delay(280); - - if (digitalRead(pinButton) == LOW) { - - counter = 0; - - colorScheme ++; - if (colorScheme > colorSchemeMax) colorScheme = 0; - EEPROM.write(0, colorScheme); - - handColor = colorSchemes[colorScheme][0]; - hourColor = colorSchemes[colorScheme][1]; - minuteColor = colorSchemes[colorScheme][2]; - secondColor = colorSchemes[colorScheme][3]; - - } else { - - clockMode ++; - if (clockMode > clockModeMax) clockMode = 0; - EEPROM.write(1, clockMode); - } - } - - if (millis() > lastDebugMessageTime + debugMessageInterval) { - lastDebugMessageTime = millis(); - printDebugMessage(); - } - - showClock(); - delay(20); - - counter ++; - if (counter > 40) counter = 40; - - timer ++; - if (timer > 255) timer = 0; + // Show clock + now = rtc.now(); + clearLeds(); + showClock(); + } } +// Display the current clock void showClock() { - - // Moving average of brightness to smooth out noisy potentiometers - int sum = 0; - - for (int i = 15; i > 0; i--) { - previousBrightness[i] = previousBrightness[i - 1]; - sum += previousBrightness[i]; - } - - previousBrightness[0] = map(analogRead(pinBrightness), 0, 1023, minBrightness, 255); - sum += previousBrightness[0]; - - currentBrightness = sum / 16; - - FastLED.setBrightness(currentBrightness); - - if (clockMode == 0) ringClock(); - else if (clockMode == 1) dotClock(); - else if (clockMode == 2) rainbowDotClock(); - else if (clockMode == 3) timeColorClock(); - else if (clockMode == 4) glowClock(); - else if (clockMode == 5) gradientHandsClock(); + switch (clockMode) { + case ClockModeRingClock: + ringClock(); + break; + case ClockModeDotClock: + dotClock(); + break; + case ClockModeDotClockColorChange: + rainbowDotClock(); + break; + case ClockModeDotClockTimeColor: + timeColorClock(); + break; + case ClockModeGlowClock: + glowClock(); + break; + } } +// Print debugging info over serial void printDebugMessage() { - Serial.print("Current date/time: "); DateTime now = rtc.now(); Serial.print(now.year(), DEC); @@ -223,246 +137,156 @@ void printDebugMessage() { Serial.println(colorScheme); Serial.print("Brightness: "); Serial.println(currentBrightness); + Serial.println(""); } // Show a ring clock void ringClock() { + int h = hourPosition(); + int m = minutePosition(); + int s = secondPosition(); - clearLeds(); - - DateTime now = rtc.now(); - - int newHour; - int newMinute; - int newSecond; - - int hour; - - if (now.hour() > 12) hour = (now.hour() - 12) * (ledRingSize / 12); - else hour = now.hour() * (ledRingSize / 12); - - newHour = hour + int(map(now.minute(), 0, 59, 0, (ledRingSize / 12) - 1)); - newMinute = int(map(now.minute(), 0, 59, 0, ledRingSize - 1)); - newSecond = int(map(now.second(), 0, 59, 0, ledRingSize - 1)); - - if (newMinute > newHour) { - for (int i = 0; i < newMinute; i++) leds[i] = minuteColor; - for (int i = 0; i < newHour; i++) leds[i] = hourColor; + if (m > h) { + for (int i = 0; i < m; i++) leds[i] = minuteColor(); + for (int i = 0; i < h; i++) leds[i] = hourColor(); } else { - for (int i = 0; i < newHour; i++) leds[i] = hourColor; - for (int i = 0; i < newMinute; i++) leds[i] = minuteColor; + for (int i = 0; i < h; i++) leds[i] = hourColor(); + for (int i = 0; i < m; i++) leds[i] = minuteColor(); } - leds[newSecond] = secondColor; + if (showSecondHand) leds[s] = secondColor(); FastLED.show(); } // Show a more traditional dot clock void dotClock() { + int h = hourPosition(); + int m = minutePosition(); + int s = secondPosition(); - clearLeds(); - - DateTime now = rtc.now(); - - int newHour; - int newMinute; - int newSecond; - - int hour; - - if (now.hour() > 12) hour = (now.hour() - 12) * (ledRingSize / 12); - else hour = now.hour() * (ledRingSize / 12); - - newHour = hour + int(map(now.minute(), 0, 59, 0, (ledRingSize / 12) - 1)); - newMinute = int(map(now.minute(), 0, 59, 0, ledRingSize - 1)); - newSecond = int(map(now.second(), 0, 59, 0, ledRingSize - 1)); - - for (int i = newHour - 1; i < newHour + 2; i++) leds[wrap(i)] = hourColor; - - leds[newMinute] = minuteColor; - - leds[newSecond] = secondColor; + for (int i = h - 1; i < h + 2; i++) leds[wrap(i)] = hourColor(); + leds[m] = minuteColor(); + if (showSecondHand) [s] = secondColor(); FastLED.show(); } // Show a dot clock with hands that change color based on their position void rainbowDotClock() { + int h = hourPosition(); + int m = minutePosition(); + int s = secondPosition(); - clearLeds(); + 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 newSecondColor = CHSV(map(now.second(), 0, 59, 0, 255), 255, 255); - DateTime now = rtc.now(); - - int newHour; - int newMinute; - int newSecond; - - int hour; - - if (now.hour() > 12) hour = (now.hour() - 12) * (ledRingSize / 12); - else hour = now.hour() * (ledRingSize / 12); - - newHour = hour + int(map(now.minute(), 0, 59, 0, (ledRingSize / 12) - 1)); - newMinute = int(map(now.minute(), 0, 59, 0, ledRingSize - 1)); - newSecond = int(map(now.second(), 0, 59, 0, ledRingSize - 1)); - - CRGB newHourColor = Wheel(int(map(newHour, 0, 12, 0, 255))); - CRGB newMinuteColor = Wheel(int(map(now.minute(), 0, 59, 0, 255))); - CRGB newSecondColor = Wheel(int(map(now.second(), 0, 59, 0, 255))); - - for (int i = newHour - 1; i < newHour + 2; i++) leds[wrap(i)] = newHourColor; - - leds[newMinute] = newMinuteColor; - - leds[newSecond] = newSecondColor; + for (int i = h - 1; i < h + 2; i++) leds[wrap(i)] = newHourColor; + leds[m] = newMinuteColor; + if (showSecondHand) leds[s] = newSecondColor; 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 decHour = decimalHour(); - clearLeds(); + CRGB pixelColor = CHSV((uint8_t)mapFloat(fmod(20.0 - decHour, 24.0), 0.0, 24.0, 0.0, 255.0), 255, 255); - DateTime now = rtc.now(); - - int newHour; - int newMinute; - int newSecond; - - int decimalHour; - - int hour; - - if (now.hour() > 12) hour = (now.hour() - 12) * (ledRingSize / 12); - else hour = now.hour() * (ledRingSize / 12); - - newHour = hour + int(map(now.minute(), 0, 59, 0, (ledRingSize / 12) - 1)); - newMinute = int(map(now.minute(), 0, 59, 0, ledRingSize - 1)); - newSecond = int(map(now.second(), 0, 59, 0, ledRingSize - 1)); - - decimalHour = now.hour() + map(now.minute() + map(now.second(), 0, 59, 0, 1), 0, 59, 0, 1); - - CRGB pixelColor = Wheel(map((20 - decimalHour) % 24, 0, 24, 0, 255)); - - for (int i = newHour - 1; i < newHour + 2; i++) leds[wrap(i)] = pixelColor; - - leds[newMinute] = pixelColor; - - leds[newSecond] = pixelColor; + for (int i = h - 1; i < h + 2; i++) leds[wrap(i)] = pixelColor; + leds[m] = pixelColor; + if (showSecondHand) leds[s] = pixelColor; FastLED.show(); } // Show a dot clock where the hands overlap with additive blending void glowClock() { - - clearLeds(); - - DateTime now = rtc.now(); - - int newHour; - int newMinute; - int newSecond; - - int hour; - - if (now.hour() > 12) hour = (now.hour() - 12) * (ledRingSize / 12); - else hour = now.hour() * (ledRingSize / 12); - - newHour = hour + int(map(now.minute(), 0, 59, 0, (ledRingSize / 12) - 1)); - newMinute = int(map(now.minute(), 0, 59, 0, ledRingSize - 1)); - newSecond = int(map(now.second(), 0, 59, 0, ledRingSize - 1)); + int h = hourPosition(); + int m = minutePosition(); + int s = secondPosition(); for (int i = -6; i < ledRingSize + 6; i++) { - int j; - for (j = 0; j <= 4; j++) { - if (newHour + j == i || newHour - j == i) blendAdd(wrap(i), CRGB(255, 0, 0), 1 - mapFloat(j, 0, 6, 0.1, 0.99)); + if (h + j == i || h - j == i) blendAdd(wrap(i), CRGB(255, 0, 0), 1 - mapFloat(j, 0.0, 6.0, 0.1, 0.99)); } - for (j = 0; j <= 2; j++) { - if (newMinute + j == i || newMinute - j == i) blendAdd(wrap(i), CRGB(0, 255, 0), 1 - mapFloat(j, 0, 3, 0.1, 0.99)); + if (m + j == i || m - j == i) blendAdd(wrap(i), CRGB(0, 255, 0), 1 - mapFloat(j, 0.0, 3.0, 0.1, 0.99)); } - - for (j = 0; j <= 1; j++) { - if (newSecond + j == i || newSecond - j == i) blendAdd(wrap(i), CRGB(0, 0, 255), 1 - mapFloat(j, 0, 1, 0.1, 0.65)); + if (showSecondHand) { + for (j = 0; j <= 1; j++) { + 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(); } -// Show a clock with gradient colored hands -void gradientHandsClock() { - - clearLeds(); - - DateTime now = rtc.now(); - - int newHour; - int newMinute; - int newSecond; - - int hour; - - if (now.hour() > 12) hour = (now.hour() - 12) * (ledRingSize / 12); - else hour = now.hour() * (ledRingSize / 12); - - newHour = hour + int(map(now.minute(), 0, 59, 0, (ledRingSize / 12) - 1)); - newMinute = int(map(now.minute(), 0, 59, 0, ledRingSize - 1)); - newSecond = int(map(now.second(), 0, 59, 0, ledRingSize - 1)); - - for (int i = 0; i < 6; i++) blendAdd(wrap(i + (newHour - 1)), gradients[gradient][i], 0.8); - - for (int i = 0; i < 4; i++) blendAdd(wrap(i + (newMinute - 1)), gradients[gradient][i + 2], 0.9); - - for (int i = 0; i < 2; i++) blendAdd(wrap(i + (newSecond - 1)), gradients[gradient][i + 4], 1); - - FastLED.show(); +// Get positions mapped to ring size +int hourPosition() { + if (twelveHour) { + int hour; + if (now.hour() > 12) hour = (now.hour() - 12) * (ledRingSize / 12); + else hour = now.hour() * (ledRingSize / 12); + return hour + int(map(now.minute(), 0, 59, 0, (ledRingSize / 12) - 1));; + } else { + int hour = now.hour() * (ledRingSize / 24); + return hour + int(map(now.minute(), 0, 59, 0, (ledRingSize / 24) - 1));; + } } -void clearLeds() { +int minutePosition() { + return map(now.minute(), 0, 59, 0, ledRingSize - 1); +} +int secondPosition() { + return map(now.second(), 0, 59, 0, ledRingSize - 1); +} + +float decimalHour() { + 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 colors +CRGB hourColor() { + return colorSchemes[colorScheme][0]; +} + +CRGB minuteColor() { + return colorSchemes[colorScheme][1]; +} + +CRGB secondColor() { + return colorSchemes[colorScheme][2]; +} + +// Clear the LED ring +void clearLeds() { for (int i = 0; i < ledRingSize; i++) leds[i] = CRGB(0, 0, 0); } // Enhanced additive blending -void blendAdd(int position, CRGB color, double brightness) { - - leds[position].r += color.r * brightness; - leds[position].g += color.g * brightness; - leds[position].b += color.b * brightness; +void blendAdd(int position, CRGB color, float factor) { + leds[position].r += color.r * factor; + leds[position].g += color.g * factor; + leds[position].b += color.b * factor; } // Wrap around LED ring int wrap(int i) { - if (i >= ledRingSize) return i - ledRingSize; else if (i < 0) return ledRingSize + i; else return i; } // Because Arduino does not -float mapFloat(float x, float in_min, float in_max, float out_min, float out_max) { - - return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; -} - -// Input a value 0 to 255 to get a color value. -// The colours are a transition r - g - b - back to r. -CRGB Wheel(byte WheelPos) { - - WheelPos = 255 - WheelPos; - - if (WheelPos < 85) return CRGB(255 - WheelPos * 3, 0, WheelPos * 3); - else if (WheelPos < 170) { - WheelPos -= 85; - return CRGB(0, WheelPos * 3, 255 - WheelPos * 3); - } else { - WheelPos -= 170; - return CRGB(WheelPos * 3, 255 - WheelPos * 3, 0); - } +float mapFloat(float x, float inMin, float inMax, float outMin, float outMax) { + return (x - inMin) * (outMax - outMin) / (inMax - inMin) + outMin; }