Add PixelStomp MUX driver (DAT=9, LD=10, CLK=11, DI=12)

- New PixelStompMux class with shift register read/write
- Read 10 buttons via DI (active LOW)
- Drive 10 LEDs via DAT (shift out + latch)
- LED startup animation uses MUX
- Switch polling reads from MUX shift register
- MUX instance shared between switch and LED drivers
This commit is contained in:
2026-06-23 13:27:24 +00:00
parent c94be67384
commit 102cae9d91
7 changed files with 194 additions and 34 deletions
+21 -15
View File
@@ -1,9 +1,8 @@
#include "led_stub.h"
#include "pixel_stomp_mux.h"
#include <Arduino.h>
static const uint8_t LED_PINS[10] = {
38, 39, 40, 41, 42, 45, 46, 47, 48, 21
};
static PixelStompMux* mux_ptr = nullptr;
DefaultLedStub::DefaultLedStub() : initialized(false) {
for (int i = 0; i < NUM_LEDS; i++) {
@@ -15,26 +14,31 @@ DefaultLedStub::DefaultLedStub() : initialized(false) {
}
}
void DefaultLedStub::set_mux(PixelStompMux* mux) {
mux_ptr = mux;
}
void DefaultLedStub::begin() {
for (int i = 0; i < NUM_LEDS; i++) {
pinMode(LED_PINS[i], OUTPUT);
digitalWrite(LED_PINS[i], LOW);
}
Serial.println("[LED] Using PixelStomp MUX for LED output");
initialized = true;
Serial.println("[LED] Startup animation...");
for (int i = 0; i < NUM_LEDS; i++) {
digitalWrite(LED_PINS[i], HIGH);
Serial.printf("[LED] LED %d ON (GPIO %d)\n", i, LED_PINS[i]);
if (mux_ptr) {
mux_ptr->set_led(i, true);
}
Serial.printf("[LED] LED %d ON\n", i);
delay(150);
}
delay(300);
for (int i = NUM_LEDS - 1; i >= 0; i--) {
digitalWrite(LED_PINS[i], LOW);
Serial.printf("[LED] LED %d OFF (GPIO %d)\n", i, LED_PINS[i]);
if (mux_ptr) {
mux_ptr->set_led(i, false);
}
Serial.printf("[LED] LED %d OFF\n", i);
delay(100);
}
@@ -53,7 +57,9 @@ void DefaultLedStub::set_led_state(uint8_t note, uint8_t channel, uint8_t veloci
led_states[led_index].active = (velocity > 0);
led_states[led_index].timestamp = millis();
digitalWrite(LED_PINS[led_index], velocity > 0 ? HIGH : LOW);
if (mux_ptr) {
mux_ptr->set_led(led_index, velocity > 0);
}
Serial.printf("[LED] Note %d -> LED %d Ch %d Vel %d (%s)\n",
note, led_index, channel, velocity,
@@ -67,9 +73,9 @@ void DefaultLedStub::clear_all() {
for (int i = 0; i < NUM_LEDS; i++) {
led_states[i].active = false;
led_states[i].velocity = 0;
if (initialized) {
digitalWrite(LED_PINS[i], LOW);
}
}
if (mux_ptr) {
mux_ptr->clear_all();
}
Serial.println("[LED] All cleared");
}