diff --git a/QuadLightsV3.ino b/QuadLightsV3.ino index f7b20b4..e67a1f9 100644 --- a/QuadLightsV3.ino +++ b/QuadLightsV3.ino @@ -64,27 +64,35 @@ Adafruit_NeoPixel ledsHeadLeft(LEDS_HEAD_LENGTH, LEDS_LEFT_PIN, NEO_GRBW + NEO_K Adafruit_NeoPixel ledsHeadRight(LEDS_HEAD_LENGTH, LEDS_RIGHT_PIN, NEO_GRBW + NEO_KHZ800); Adafruit_NeoPixel ledsDash(LEDS_DASH_LENGTH, LEDS_DASH_PIN, NEO_GRBW + NEO_KHZ800); -const uint32_t COLOR_OFF = ledsTail.Color(0, 0, 0, 0); -const uint32_t COLOR_WHITE = ledsTail.Color(0, 0, 0, 255); -const uint32_t COLOR_WHITE_FULL = ledsTail.Color(255, 255, 255, 255); -const uint32_t COLOR_WHITE_DIM = ledsTail.Color(0, 0, 0, 100); -const uint32_t COLOR_RED = ledsTail.Color(255, 0, 0, 0); -const uint32_t COLOR_AMBER = ledsTail.Color(255, 50, 0, 0); -const uint32_t COLOR_POLICE_BLUE = ledsTail.Color(0, 0, 255, 0); -const uint32_t COLOR_POLICE_RED = ledsTail.Color(255, 0, 0, 0); - enum Direction { LEFT, RIGHT }; enum Mode { MODE_HEAD, - MODE_POLICE, MODE_HAZARD, + MODE_POLICE, MODE_RAINBOW, MODE_COUNT, }; // Mode activeMode = MODE_HEAD; -Mode activeMode = MODE_HAZARD; +Mode activeMode = MODE_RAINBOW; + +uint32_t colorHSV(float hue, float sat = 1.0, float val = 1.0) { + return Adafruit_NeoPixel::ColorHSV( + (uint16_t)(hue / 360.0 * 65535), + (uint8_t)(sat * 255), + (uint8_t)(val * 255) + ); +} + +const uint32_t COLOR_OFF = ledsTail.Color(0, 0, 0, 0); +const uint32_t COLOR_WHITE = ledsTail.Color(0, 0, 0, 255); +const uint32_t COLOR_WHITE_FULL = ledsTail.Color(255, 255, 255, 255); +const uint32_t COLOR_WHITE_DIM = ledsTail.Color(0, 0, 0, 100); +const uint32_t COLOR_RED = ledsTail.Color(255, 0, 0, 0); +const uint32_t COLOR_AMBER = colorHSV(10); // easier value fade +const uint32_t COLOR_POLICE_BLUE = ledsTail.Color(0, 0, 255, 0); +const uint32_t COLOR_POLICE_RED = ledsTail.Color(255, 0, 0, 0); unsigned long animationFrame = 0; unsigned long lastFrame = 0; @@ -161,21 +169,13 @@ void animateReverse() { ledsTail.fill(COLOR_WHITE); } -uint32_t colorHSV(float hue, float sat = 1.0, float val = 1.0) { - return Adafruit_NeoPixel::ColorHSV( - (uint16_t)(hue / 360.0 * 65535), - (uint8_t)(sat * 255), - (uint8_t)(val * 255) - ); -} - constexpr int INDICATOR_DURATION = 3200; // total ms constexpr int INDICATOR_HOLD_FRAMES = 15; constexpr int INDICATOR_OFF_FRAMES = 20; constexpr float INDICATOR_SPEED = 2; void animateIndicator(Direction direction) { - Adafruit_NeoPixel& ledsTarget = direction == LEFT // reference, not pointer + Adafruit_NeoPixel& ledsTarget = direction == LEFT ? ledsHeadLeft : ledsHeadRight; @@ -210,6 +210,14 @@ void animateIndicator(Direction direction) { ledsTarget.fill(COLOR_OFF, 0, LEDS_EDGE_LENGTH); } } + + if (indicatorFrame < sweepEnd) { + ledsDash.setPixelColor(dashTargetIndex, colorHSV(10, 1, (float)indicatorFrame / sweepEnd)); + } else if (indicatorFrame < holdEnd) { + ledsDash.setPixelColor(dashTargetIndex, COLOR_AMBER); + } else { + ledsDash.setPixelColor(dashTargetIndex, COLOR_OFF); + } } constexpr float POLICE_SPEED = 0.75;