Rewrite MUX: WS2812C LEDs (NeoPixel) + 74HC165 buttons

PixelStomp MUX uses:
- WS2812C LEDs: one data line via DAT (GPIO 9), NeoPixel protocol
- 74HC165 shift register: LD/CLK/DI for reading 8 button states

Changes:
- Use Adafruit NeoPixel library for LED control
- Proper 74HC165 parallel-load shift-in for buttons
- 8 switches + 8 LEDs (was incorrectly 10)
- Diagnostic commands: dump, ledtest, red, green, blue, read
This commit is contained in:
2026-06-23 13:38:51 +00:00
parent 2dfd016b76
commit 07e5cd8994
8 changed files with 122 additions and 139 deletions
+36 -19
View File
@@ -19,34 +19,47 @@ void DefaultLedStub::set_mux(PixelStompMux* mux) {
}
void DefaultLedStub::begin() {
Serial.println("[LED] Using PixelStomp MUX for LED output");
Serial.println("[LED] Using WS2812C via PixelStomp MUX");
initialized = true;
if (!mux_ptr) {
Serial.println("[LED] ERROR: No MUX configured");
return;
}
Serial.println("[LED] Startup animation...");
for (int i = 0; i < NUM_LEDS; i++) {
if (mux_ptr) {
mux_ptr->set_led(i, true);
uint32_t colors[] = {
0xFF0000, // Red
0x00FF00, // Green
0x0000FF, // Blue
0xFFFF00, // Yellow
0xFF00FF, // Magenta
0x00FFFF, // Cyan
0xFFFFFF, // White
};
int num_colors = sizeof(colors) / sizeof(colors[0]);
for (int c = 0; c < num_colors; c++) {
uint32_t color = colors[c];
uint8_t r = (color >> 16) & 0xFF;
uint8_t g = (color >> 8) & 0xFF;
uint8_t b = color & 0xFF;
for (int i = 0; i < NUM_LEDS; i++) {
mux_ptr->set_led_color(i, r, g, b);
}
Serial.printf("[LED] LED %d ON\n", i);
delay(150);
}
delay(300);
for (int i = NUM_LEDS - 1; i >= 0; i--) {
if (mux_ptr) {
mux_ptr->set_led(i, false);
}
Serial.printf("[LED] LED %d OFF\n", i);
delay(100);
mux_ptr->show();
Serial.printf("[LED] Colour %d: R=%d G=%d B=%d\n", c, r, g, b);
delay(200);
}
clear_all();
Serial.println("[LED] Startup complete");
}
void DefaultLedStub::set_led_state(uint8_t note, uint8_t channel, uint8_t velocity) {
if (!initialized) return;
if (!initialized || !mux_ptr) return;
uint8_t led_index = note_to_index(note);
@@ -57,9 +70,13 @@ 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();
if (mux_ptr) {
mux_ptr->set_led(led_index, velocity > 0);
if (velocity > 0) {
uint8_t brightness = map(velocity, 1, 127, 30, 255);
mux_ptr->set_led_color(led_index, brightness, brightness, brightness);
} else {
mux_ptr->set_led_color(led_index, 0, 0, 0);
}
mux_ptr->show();
Serial.printf("[LED] Note %d -> LED %d Ch %d Vel %d (%s)\n",
note, led_index, channel, velocity,