fade out rainbow animation during animation
This commit is contained in:
parent
c292676a0a
commit
692ac54fe8
@ -201,29 +201,25 @@ void led_anim_knight_rider(ULONG _) {
|
||||
void led_anim_rainbow(ULONG _) {
|
||||
size_t tail = 0;
|
||||
float offset = 0.0f;
|
||||
const float max_offset = 360.0f * 2;
|
||||
float brightness = 1.0f;
|
||||
// Moving rainbow
|
||||
uint32_t start = HAL_GetTick();
|
||||
while (offset < 360) {
|
||||
while (offset < max_offset) {
|
||||
for (size_t i = 0; i < N_LEDS; i++) {
|
||||
size_t led = (tail + i) % N_LEDS;
|
||||
uint8_t r, g, b;
|
||||
float hue = fmodf(offset + i * 360.0f / N_LEDS, 360.0f);
|
||||
led_hsv_to_rgb(hue, 1, 1, &r, &g, &b);
|
||||
// fade out during last hue rotation
|
||||
if (offset >= max_offset - 360.0f) {
|
||||
brightness = (max_offset - offset) / 360.0f;
|
||||
}
|
||||
led_hsv_to_rgb(hue, 1, brightness, &r, &g, &b);
|
||||
led_set(led, r, g, b);
|
||||
}
|
||||
offset = (HAL_GetTick() - start) / 5.0f;
|
||||
tx_thread_sleep(1);
|
||||
}
|
||||
// Fade-out
|
||||
for (float val = 1.0f; val > 0; val -= 0.1f) {
|
||||
for (size_t i = 0; i < N_LEDS; i++) {
|
||||
float hue = fmodf(offset + i * 360.0f / N_LEDS, 360.0f);
|
||||
uint8_t r, g, b;
|
||||
led_hsv_to_rgb(hue, 1, val, &r, &g, &b);
|
||||
led_set(i, r, g, b);
|
||||
}
|
||||
tx_thread_sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
void led_anim_blinker(uint8_t r, uint8_t g, uint8_t b,
|
||||
|
Loading…
x
Reference in New Issue
Block a user