Added brake light animation on pedal release.

This commit is contained in:
ThePendulum
2026-05-01 05:39:36 +02:00
parent d6f32a03fd
commit abea37e15e

View File

@@ -92,6 +92,7 @@ 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 = ledsTail.Color(0, 0, 0, 255);
const uint32_t COLOR_WHITE_FULL = ledsTail.Color(255, 255, 255, 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_WHITE_DIM = ledsTail.Color(0, 0, 0, 100);
const uint32_t COLOR_RED_DIM = ledsTail.Color(150, 0, 0, 0);
const uint32_t COLOR_RED = ledsTail.Color(255, 0, 0, 0); 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_AMBER = colorHSV(10); // easier value fade
const uint32_t COLOR_POLICE_BLUE = ledsTail.Color(0, 0, 255, 0); const uint32_t COLOR_POLICE_BLUE = ledsTail.Color(0, 0, 255, 0);
@@ -101,6 +102,7 @@ unsigned long animationFrame = 0;
unsigned long lastFrame = 0; unsigned long lastFrame = 0;
unsigned long lastPedalPress = millis(); unsigned long lastPedalPress = millis();
unsigned long lastPedalRelease = 0;
bool isReversing = false; bool isReversing = false;
unsigned long indicatorLeftStart = 0; unsigned long indicatorLeftStart = 0;
@@ -161,17 +163,24 @@ void animateHeadlights() {
} }
void animateTailLight() { void animateTailLight() {
ledsTail.fill(COLOR_RED); ledsTail.fill(COLOR_OFF, 0, LEDS_TAIL_LENGTH);
ledsTail.fill(COLOR_RED, LEDS_TAIL_SIDE_LENGTH, LEDS_TAIL_LENGTH - LEDS_TAIL_SIDE_LENGTH * 2);
} }
void animateRightTailSide(uint32_t color) { void animateRightTailSide(uint32_t color, bool withMargin = true) {
ledsTail.fill(color, 0, LEDS_TAIL_SIDE_LENGTH); ledsTail.fill(color, 0, LEDS_TAIL_SIDE_LENGTH);
ledsTail.fill(COLOR_OFF, LEDS_TAIL_SIDE_LENGTH, LEDS_TAIL_SIDE_MARGIN);
if (withMargin) {
ledsTail.fill(COLOR_OFF, LEDS_TAIL_SIDE_LENGTH, LEDS_TAIL_SIDE_MARGIN);
}
} }
void animateLeftTailSide(uint32_t color) { void animateLeftTailSide(uint32_t color, bool withMargin = true) {
ledsTail.fill(color, LEDS_TAIL_LENGTH - LEDS_TAIL_SIDE_LENGTH, LEDS_TAIL_SIDE_LENGTH); ledsTail.fill(color, LEDS_TAIL_LENGTH - LEDS_TAIL_SIDE_LENGTH, LEDS_TAIL_SIDE_LENGTH);
ledsTail.fill(COLOR_OFF, LEDS_TAIL_LENGTH - LEDS_TAIL_SIDE_LENGTH - LEDS_TAIL_SIDE_MARGIN, LEDS_TAIL_SIDE_MARGIN);
if (withMargin) {
ledsTail.fill(COLOR_OFF, LEDS_TAIL_LENGTH - LEDS_TAIL_SIDE_LENGTH - LEDS_TAIL_SIDE_MARGIN, LEDS_TAIL_SIDE_MARGIN);
}
} }
void animateDash() { void animateDash() {
@@ -182,6 +191,11 @@ void animateReverse() {
ledsTail.fill(COLOR_WHITE); ledsTail.fill(COLOR_WHITE);
} }
void animateBrake() {
animateLeftTailSide(COLOR_RED, false);
animateRightTailSide(COLOR_RED, false);
}
constexpr int INDICATOR_DURATION = 3200; // total ms constexpr int INDICATOR_DURATION = 3200; // total ms
constexpr int INDICATOR_HOLD_FRAMES = 15; constexpr int INDICATOR_HOLD_FRAMES = 15;
constexpr int INDICATOR_OFF_FRAMES = 20; constexpr int INDICATOR_OFF_FRAMES = 20;
@@ -224,7 +238,7 @@ void animateIndicator(Direction direction) {
? LEDS_TAIL_LEFT_RANGE ? LEDS_TAIL_LEFT_RANGE
: LEDS_TAIL_RIGHT_RANGE; : LEDS_TAIL_RIGHT_RANGE;
void (*animateTailSide)(uint32_t) = direction == LEFT void (*animateTailSide)(uint32_t, bool) = direction == LEFT
? animateLeftTailSide ? animateLeftTailSide
: animateRightTailSide; : animateRightTailSide;
@@ -235,13 +249,13 @@ void animateIndicator(Direction direction) {
if (indicatorFrame < sweepEnd) { if (indicatorFrame < sweepEnd) {
const int colorAmberFaded = colorHSV(10, 1, (float)indicatorFrame / sweepEnd); const int colorAmberFaded = colorHSV(10, 1, (float)indicatorFrame / sweepEnd);
animateTailSide(colorAmberFaded); animateTailSide(colorAmberFaded, true);
ledsDash.setPixelColor(dashIndex, colorAmberFaded); ledsDash.setPixelColor(dashIndex, colorAmberFaded);
} else if (indicatorFrame < holdEnd) { } else if (indicatorFrame < holdEnd) {
animateTailSide(COLOR_AMBER); animateTailSide(COLOR_AMBER, true);
ledsDash.setPixelColor(dashIndex, COLOR_AMBER); ledsDash.setPixelColor(dashIndex, COLOR_AMBER);
} else { } else {
animateTailSide(COLOR_OFF); animateTailSide(COLOR_OFF, true);
ledsDash.setPixelColor(dashIndex, COLOR_OFF); ledsDash.setPixelColor(dashIndex, COLOR_OFF);
} }
} }
@@ -355,6 +369,10 @@ void animate(long now) {
animateIndicator(RIGHT); animateIndicator(RIGHT);
} }
if (now - lastPedalRelease < 1500) {
animateBrake();
}
if (activeMode == MODE_RAINBOW) { if (activeMode == MODE_RAINBOW) {
animateRainbow(); animateRainbow();
} }
@@ -475,6 +493,10 @@ void loop() {
Serial.println("PEDAL FORWARD"); Serial.println("PEDAL FORWARD");
} }
if (pedal.released()) {
lastPedalRelease = now;
}
if (!isOff && now - lastFrame >= ANIMATION_INTERVAL) { if (!isOff && now - lastFrame >= ANIMATION_INTERVAL) {
lastFrame += ANIMATION_INTERVAL; lastFrame += ANIMATION_INTERVAL;
animationFrame += 1; animationFrame += 1;