Using separate animation frame for rainbow to prevent reset during indicators.
This commit is contained in:
@@ -74,11 +74,12 @@ enum Mode {
|
|||||||
MODE_HAZARD,
|
MODE_HAZARD,
|
||||||
MODE_POLICE,
|
MODE_POLICE,
|
||||||
MODE_RAINBOW,
|
MODE_RAINBOW,
|
||||||
|
MODE_KITT,
|
||||||
MODE_COUNT,
|
MODE_COUNT,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Mode activeMode = MODE_HEAD;
|
// Mode activeMode = MODE_HEAD;
|
||||||
Mode activeMode = MODE_RAINBOW;
|
Mode activeMode = MODE_KITT;
|
||||||
|
|
||||||
uint32_t colorHSV(float hue, float sat = 1.0, float val = 1.0) {
|
uint32_t colorHSV(float hue, float sat = 1.0, float val = 1.0) {
|
||||||
return Adafruit_NeoPixel::ColorHSV(
|
return Adafruit_NeoPixel::ColorHSV(
|
||||||
@@ -99,6 +100,7 @@ const uint32_t COLOR_POLICE_BLUE = ledsTail.Color(0, 0, 255, 0);
|
|||||||
const uint32_t COLOR_POLICE_RED = ledsTail.Color(255, 0, 0, 0);
|
const uint32_t COLOR_POLICE_RED = ledsTail.Color(255, 0, 0, 0);
|
||||||
|
|
||||||
unsigned long animationFrame = 0;
|
unsigned long animationFrame = 0;
|
||||||
|
unsigned long stableAnimationFrame = 0;
|
||||||
unsigned long lastFrame = 0;
|
unsigned long lastFrame = 0;
|
||||||
|
|
||||||
unsigned long lastPedalPress = millis();
|
unsigned long lastPedalPress = millis();
|
||||||
@@ -234,10 +236,6 @@ void animateIndicator(Direction direction) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const int* tailRange = direction == LEFT
|
|
||||||
? LEDS_TAIL_LEFT_RANGE
|
|
||||||
: LEDS_TAIL_RIGHT_RANGE;
|
|
||||||
|
|
||||||
void (*animateTailSide)(uint32_t, bool) = direction == LEFT
|
void (*animateTailSide)(uint32_t, bool) = direction == LEFT
|
||||||
? animateLeftTailSide
|
? animateLeftTailSide
|
||||||
: animateRightTailSide;
|
: animateRightTailSide;
|
||||||
@@ -322,32 +320,37 @@ void animatePolice() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
constexpr float RAINBOW_SPEED = 2.0;
|
constexpr float RAINBOW_SPEED = 2.0;
|
||||||
constexpr float RAINBOW_DENSITY = 5.0;
|
constexpr float RAINBOW_DENSITY = 10.0;
|
||||||
|
|
||||||
void animateRainbow() {
|
void animateRainbow() {
|
||||||
for (int ledIndex = 0; ledIndex < LEDS_HEAD_LENGTH; ledIndex++) {
|
// EDGES, flowing color
|
||||||
const uint32_t pixelColor = colorHSV((animationFrame * RAINBOW_SPEED) + (ledIndex * RAINBOW_DENSITY));
|
for (int ledIndex = LEDS_TOP_LENGTH - 1; ledIndex >= 0; ledIndex--) {
|
||||||
|
const uint32_t pixelColor = colorHSV((stableAnimationFrame * RAINBOW_SPEED) + (ledIndex * RAINBOW_DENSITY));
|
||||||
|
|
||||||
ledsHeadLeft.setPixelColor(ledIndex, pixelColor);
|
ledsHeadLeft.setPixelColor(ledIndex, pixelColor);
|
||||||
|
ledsHeadLeft.setPixelColor(LEDS_EDGE_LENGTH - ledIndex, pixelColor);
|
||||||
|
|
||||||
ledsHeadRight.setPixelColor(ledIndex, pixelColor);
|
ledsHeadRight.setPixelColor(ledIndex, pixelColor);
|
||||||
|
ledsHeadRight.setPixelColor(LEDS_EDGE_LENGTH - ledIndex, pixelColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// RINGS, single color
|
||||||
|
ledsHeadLeft.fill(colorHSV(stableAnimationFrame * RAINBOW_SPEED), LEDS_EDGE_LENGTH, LEDS_RING_LENGTH);
|
||||||
|
ledsHeadRight.fill(colorHSV(stableAnimationFrame * RAINBOW_SPEED), LEDS_EDGE_LENGTH, LEDS_RING_LENGTH);
|
||||||
|
|
||||||
for (int ledIndex = 0; ledIndex < LEDS_TAIL_LENGTH; ledIndex++) {
|
for (int ledIndex = 0; ledIndex < LEDS_TAIL_LENGTH; ledIndex++) {
|
||||||
const uint32_t pixelColor = ledsHeadLeft.ColorHSV((animationFrame * 1000 * RAINBOW_SPEED) + (ledIndex * 1000 * RAINBOW_DENSITY * 5), 255, 255);
|
const int distFromCenter = abs(ledIndex * 2 - (LEDS_TAIL_LENGTH - 1));
|
||||||
|
const uint32_t pixelColor = colorHSV((stableAnimationFrame * RAINBOW_SPEED) - (distFromCenter * RAINBOW_DENSITY * 2));
|
||||||
|
|
||||||
if (ledIndex <= 5) {
|
|
||||||
ledsTail.setPixelColor(ledIndex, pixelColor);
|
ledsTail.setPixelColor(ledIndex, pixelColor);
|
||||||
} else {
|
|
||||||
ledsTail.setPixelColor(LEDS_TAIL_LENGTH - ledIndex, pixelColor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ledsDash.setPixelColor(1, colorHSV(stableAnimationFrame * RAINBOW_SPEED));
|
||||||
|
ledsDash.setPixelColor(0, colorHSV(stableAnimationFrame * RAINBOW_SPEED + 90));
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
ledsTail.fill(colorHSV(animationFrame * RAINBOW_SPEED));
|
void animateKitt() {
|
||||||
|
// not implemented
|
||||||
ledsDash.setPixelColor(1, colorHSV(animationFrame * RAINBOW_SPEED));
|
|
||||||
ledsDash.setPixelColor(0, colorHSV(animationFrame * RAINBOW_SPEED + 90));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void animate(long now) {
|
void animate(long now) {
|
||||||
@@ -369,6 +372,10 @@ void animate(long now) {
|
|||||||
animateIndicator(RIGHT);
|
animateIndicator(RIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (activeMode == MODE_KITT) {
|
||||||
|
animateKitt();
|
||||||
|
}
|
||||||
|
|
||||||
if (now - lastPedalRelease < 1500) {
|
if (now - lastPedalRelease < 1500) {
|
||||||
animateBrake();
|
animateBrake();
|
||||||
}
|
}
|
||||||
@@ -415,6 +422,7 @@ void shutdown() {
|
|||||||
void restart() {
|
void restart() {
|
||||||
lastFrame = millis();
|
lastFrame = millis();
|
||||||
animationFrame = 0;
|
animationFrame = 0;
|
||||||
|
stableAnimationFrame = 0;
|
||||||
isOff = false;
|
isOff = false;
|
||||||
|
|
||||||
digitalWrite(PIN_BUCK, BUCK_ON);
|
digitalWrite(PIN_BUCK, BUCK_ON);
|
||||||
@@ -500,6 +508,7 @@ void loop() {
|
|||||||
if (!isOff && now - lastFrame >= ANIMATION_INTERVAL) {
|
if (!isOff && now - lastFrame >= ANIMATION_INTERVAL) {
|
||||||
lastFrame += ANIMATION_INTERVAL;
|
lastFrame += ANIMATION_INTERVAL;
|
||||||
animationFrame += 1;
|
animationFrame += 1;
|
||||||
|
stableAnimationFrame += 1;
|
||||||
|
|
||||||
animate(now);
|
animate(now);
|
||||||
render();
|
render();
|
||||||
|
|||||||
Reference in New Issue
Block a user