Fix pulse shape and button responsiveness
- Pulse shape: instant-on at beat, quick fade to 0 by phase 0.25 (was smooth sine wave - didn't show exact timing) - Active LEDs no longer overridden by update() - they keep their set_led_state() color, restoring button press responsiveness - Pixel 6 only pulses when not active (acts as visual metronome) When active as a loop trigger, stays at full brightness
This commit is contained in:
+12
-23
@@ -1,7 +1,6 @@
|
||||
#include "led_stub.h"
|
||||
#include "pixel_stomp_mux.h"
|
||||
#include <Arduino.h>
|
||||
#include <math.h>
|
||||
|
||||
static PixelStompMux* mux_ptr = nullptr;
|
||||
|
||||
@@ -316,30 +315,20 @@ void DefaultLedStub::update() {
|
||||
last_pulse_update = now;
|
||||
|
||||
float phase = (now % beat_interval_ms) / (float)beat_interval_ms;
|
||||
float pulse = sinf(M_PI * phase);
|
||||
|
||||
bool active = false;
|
||||
for (int i = 0; i < NUM_LEDS; i++) {
|
||||
if (led_states[i].active) {
|
||||
active = true;
|
||||
float brightness = 0.5f + 0.5f * pulse;
|
||||
uint32_t base = pad_base_colors[i];
|
||||
uint8_t r = (uint8_t)(((base >> 16) & 0xFF) * brightness);
|
||||
uint8_t g = (uint8_t)(((base >> 8) & 0xFF) * brightness);
|
||||
uint8_t b = (uint8_t)((base & 0xFF) * brightness);
|
||||
mux_ptr->set_led_color(i, r, g, b);
|
||||
} else if (i == 6) {
|
||||
active = true;
|
||||
float brightness = 0.3f + 0.7f * pulse;
|
||||
uint32_t base = pad_base_colors[6];
|
||||
uint8_t r = (uint8_t)(((base >> 16) & 0xFF) * brightness);
|
||||
uint8_t g = (uint8_t)(((base >> 8) & 0xFF) * brightness);
|
||||
uint8_t b = (uint8_t)((base & 0xFF) * brightness);
|
||||
mux_ptr->set_led_color(6, r, g, b);
|
||||
}
|
||||
}
|
||||
// Instant-on at beat, quick fade to 0 by phase 0.25
|
||||
float pulse = 1.0f - phase * 4.0f;
|
||||
if (pulse < 0.0f) pulse = 0.0f;
|
||||
|
||||
if (active) {
|
||||
// Active LEDs keep their last set_led_state() color — don't override.
|
||||
// Pixel 6 pulses only when not active (visual metronome for timing).
|
||||
if (!led_states[6].active) {
|
||||
float brightness = 0.3f + 0.7f * pulse;
|
||||
uint32_t base = pad_base_colors[6];
|
||||
uint8_t r = (uint8_t)(((base >> 16) & 0xFF) * brightness);
|
||||
uint8_t g = (uint8_t)(((base >> 8) & 0xFF) * brightness);
|
||||
uint8_t b = (uint8_t)((base & 0xFF) * brightness);
|
||||
mux_ptr->set_led_color(6, r, g, b);
|
||||
mux_ptr->show();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user