Pixel 6 pulses on MIDI Clock beat (0xF8) - all on Core 0
- Detect 0xF8 in midi_transport.cpp (runs on Core 0) - Every 24th tick = beat, flash pixel 6 white - Instant-on, quadratic fade over 80ms, restore to dim - All FastLED calls stay on Core 0, no cross-core conflict
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
|
||||
extern volatile uint32_t midi_tick_count;
|
||||
|
||||
struct MidiEvent {
|
||||
enum Type {
|
||||
NOTE_ON,
|
||||
|
||||
+26
-1
@@ -25,10 +25,35 @@ TaskHandle_t midi_task_handle = NULL;
|
||||
|
||||
void midi_task(void* parameter) {
|
||||
Serial.println("[TASK] MIDI task started on core 0");
|
||||
|
||||
uint32_t last_beat = 0;
|
||||
uint32_t flash_start = 0;
|
||||
|
||||
while (true) {
|
||||
midi_transport.update();
|
||||
exp_pedal.update(midi_transport);
|
||||
|
||||
uint32_t beat = midi_tick_count / 24;
|
||||
if (beat != last_beat) {
|
||||
last_beat = beat;
|
||||
flash_start = millis();
|
||||
mux.set_led_color(6, 255, 255, 255);
|
||||
mux.show();
|
||||
}
|
||||
|
||||
if (flash_start > 0) {
|
||||
uint32_t elapsed = millis() - flash_start;
|
||||
if (elapsed >= 80) {
|
||||
mux.set_led_color(6, 20, 20, 20);
|
||||
mux.show();
|
||||
flash_start = 0;
|
||||
} else {
|
||||
float b = 1.0f - (float)elapsed / 80.0f;
|
||||
uint8_t v = (uint8_t)(255 * b * b);
|
||||
mux.set_led_color(6, v, v, v);
|
||||
mux.show();
|
||||
}
|
||||
}
|
||||
|
||||
vTaskDelay(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#include <Arduino.h>
|
||||
#include "Adafruit_TinyUSB.h"
|
||||
|
||||
volatile uint32_t midi_tick_count = 0;
|
||||
|
||||
static Adafruit_USBD_MIDI usb_midi;
|
||||
|
||||
UsbMidiTransport::UsbMidiTransport() : initialized(false) {
|
||||
@@ -51,6 +53,12 @@ void UsbMidiTransport::update() {
|
||||
while (usb_midi.available()) {
|
||||
uint8_t packet[4];
|
||||
if (usb_midi.readPacket(packet)) {
|
||||
uint8_t cin = packet[0] & 0x0F;
|
||||
if (cin == 0x0F) {
|
||||
if (packet[1] == 0xF8) midi_tick_count++;
|
||||
continue;
|
||||
}
|
||||
|
||||
MidiEvent event;
|
||||
parse_midi_packet(packet, 4, event);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user