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:
+7
-18
@@ -1,7 +1,6 @@
|
|||||||
#include "led_stub.h"
|
#include "led_stub.h"
|
||||||
#include "pixel_stomp_mux.h"
|
#include "pixel_stomp_mux.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
static PixelStompMux* mux_ptr = nullptr;
|
static PixelStompMux* mux_ptr = nullptr;
|
||||||
|
|
||||||
@@ -316,30 +315,20 @@ void DefaultLedStub::update() {
|
|||||||
last_pulse_update = now;
|
last_pulse_update = now;
|
||||||
|
|
||||||
float phase = (now % beat_interval_ms) / (float)beat_interval_ms;
|
float phase = (now % beat_interval_ms) / (float)beat_interval_ms;
|
||||||
float pulse = sinf(M_PI * phase);
|
|
||||||
|
|
||||||
bool active = false;
|
// Instant-on at beat, quick fade to 0 by phase 0.25
|
||||||
for (int i = 0; i < NUM_LEDS; i++) {
|
float pulse = 1.0f - phase * 4.0f;
|
||||||
if (led_states[i].active) {
|
if (pulse < 0.0f) pulse = 0.0f;
|
||||||
active = true;
|
|
||||||
float brightness = 0.5f + 0.5f * pulse;
|
// Active LEDs keep their last set_led_state() color — don't override.
|
||||||
uint32_t base = pad_base_colors[i];
|
// Pixel 6 pulses only when not active (visual metronome for timing).
|
||||||
uint8_t r = (uint8_t)(((base >> 16) & 0xFF) * brightness);
|
if (!led_states[6].active) {
|
||||||
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;
|
float brightness = 0.3f + 0.7f * pulse;
|
||||||
uint32_t base = pad_base_colors[6];
|
uint32_t base = pad_base_colors[6];
|
||||||
uint8_t r = (uint8_t)(((base >> 16) & 0xFF) * brightness);
|
uint8_t r = (uint8_t)(((base >> 16) & 0xFF) * brightness);
|
||||||
uint8_t g = (uint8_t)(((base >> 8) & 0xFF) * brightness);
|
uint8_t g = (uint8_t)(((base >> 8) & 0xFF) * brightness);
|
||||||
uint8_t b = (uint8_t)((base & 0xFF) * brightness);
|
uint8_t b = (uint8_t)((base & 0xFF) * brightness);
|
||||||
mux_ptr->set_led_color(6, r, g, b);
|
mux_ptr->set_led_color(6, r, g, b);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (active) {
|
|
||||||
mux_ptr->show();
|
mux_ptr->show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user