Capture tick 0 (last_beat=UINT32_MAX) so downbeat is not skipped

This commit is contained in:
ash
2026-07-03 08:13:08 +00:00
parent e1507d5d7c
commit 3226986709
+5 -4
View File
@@ -29,7 +29,8 @@ void midi_task(void* parameter) {
Serial.println("[TASK] MIDI task started on core 0"); Serial.println("[TASK] MIDI task started on core 0");
// Beat timing fixes for precise beat alignment - sync to real MIDI time, not hardcoded tempo // Beat timing fixes for precise beat alignment - sync to real MIDI time, not hardcoded tempo
uint32_t last_beat = 0; // UINT32_MAX ensures tick 0 (first 0xF8 after START) triggers a flash
uint32_t last_beat = UINT32_MAX;
uint32_t flash_start = 0; uint32_t flash_start = 0;
while (true) { while (true) {
@@ -44,8 +45,8 @@ void midi_task(void* parameter) {
if (current_beat != last_beat) { if (current_beat != last_beat) {
last_beat = current_beat; last_beat = current_beat;
flash_start = now + flash_latency; flash_start = now + flash_latency;
// Beat 1 (every 4th) = RED, others = WHITE // Beat 1 = red on current_beat % 4 == 0, others = white
if (current_beat % 4 == 1) { if (current_beat % 4 == 0) {
mux.set_led_color(6, 255, 0, 0); mux.set_led_color(6, 255, 0, 0);
} else { } else {
mux.set_led_color(6, 255, 255, 255); mux.set_led_color(6, 255, 255, 255);
@@ -54,7 +55,7 @@ void midi_task(void* parameter) {
if (flash_start > 0 && now >= flash_start) { if (flash_start > 0 && now >= flash_start) {
mux.show(); mux.show();
uint32_t hold = (last_beat % 4 == 1) ? 100 : 50; uint32_t hold = (last_beat % 4 == 0) ? 100 : 50;
uint32_t elapsed = now - flash_start; uint32_t elapsed = now - flash_start;
if (elapsed >= hold) { if (elapsed >= hold) {
mux.set_led_color(6, 20, 20, 20); mux.set_led_color(6, 20, 20, 20);