From d2d5d7dc4b450dde6c2043a3e3498ca99e29d680 Mon Sep 17 00:00:00 2001 From: localhorst Date: Tue, 6 Jan 2026 22:33:28 +0100 Subject: [PATCH] fix chase animation --- main/animation.c | 50 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/main/animation.c b/main/animation.c index 1500ddf..be05627 100644 --- a/main/animation.c +++ b/main/animation.c @@ -251,25 +251,45 @@ static void anim_chase(void) // Red dot sweeping with trailing dots led_clear_all(); - uint16_t num_leds = led_get_num_leds_a() + led_get_num_leds_b(); - int16_t pos = beatsin16(40, 0, num_leds - 1); + uint16_t num_leds_a = led_get_num_leds_a(); + uint16_t num_leds_b = led_get_num_leds_b(); + uint16_t total_leds = num_leds_a + num_leds_b; + + // Get oscillating position across both strips + int16_t center_pos = beatsin16(40, 0, total_leds - 1); rgb_t red = {255, 0, 0}; - // Set main dot and trailing dots - for (int offset = -2; offset <= 2; offset++) + // Draw center dot with dimmed trailing dots (3 dots total: center ±1) + for (int8_t offset = -1; offset <= 1; offset++) { - int16_t led_pos = pos + offset; - if (led_pos >= 0 && led_pos < num_leds) + int16_t led_pos = center_pos + offset; + + // Skip if position is out of bounds + if (led_pos < 0 || led_pos >= total_leds) + continue; + + // Calculate brightness based on distance from center + uint8_t brightness = (offset == 0) ? 255 : 64; // Center: full, trailing: 25% + + // Create dimmed color + rgb_t dimmed_red = { + (red.r * brightness) / 255, + (red.g * brightness) / 255, + (red.b * brightness) / 255}; + + // Map virtual position to physical LED + if (led_pos < num_leds_a) { - if (led_pos < led_get_num_leds_a()) - { - led_set_pixel_a(led_pos, red); - } - else - { - led_set_pixel_b(led_pos - led_get_num_leds_a(), red); - } + // Strip A (mirrored: position 0 maps to last LED) + uint16_t strip_a_index = num_leds_a - led_pos - 1; + led_set_pixel_a(strip_a_index, dimmed_red); + } + else + { + // Strip B (direct mapping) + uint16_t strip_b_index = led_pos - num_leds_a; + led_set_pixel_b(strip_b_index, dimmed_red); } } } @@ -409,7 +429,7 @@ void animation_update(void) anim_navigation(); break; case ANIM_CHASE: - // anim_chase(); + anim_chase(); break; case ANIM_CHASE_RGB: // anim_chase_rgb();