From 5de4de4f1a3b8df1a0732a47b01677a2e225197c Mon Sep 17 00:00:00 2001 From: Ashley Strahle Date: Tue, 23 Jun 2026 13:56:05 +0000 Subject: [PATCH] Switch from NeoPixel to FastLED for ESP32-S3 LED reliability FastLED has better ESP32 support and handles timing/RMT properly. - Use CRGB array instead of Adafruit_NeoPixel - FastLED.show() is more reliable on ESP32-S3 - probe command now tests all LEDs at max brightness --- include/pixel_stomp_mux.h | 5 ++--- platformio.ini | 2 +- src/led_stub.cpp | 24 ++++++++++----------- src/pixel_stomp_mux.cpp | 44 ++++++++++++++++++--------------------- 4 files changed, 35 insertions(+), 40 deletions(-) diff --git a/include/pixel_stomp_mux.h b/include/pixel_stomp_mux.h index 0707ec4..6a51561 100644 --- a/include/pixel_stomp_mux.h +++ b/include/pixel_stomp_mux.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include class PixelStompMux { public: @@ -29,8 +29,7 @@ private: uint8_t pin_clk; uint8_t pin_di; - Adafruit_NeoPixel* strip; - + CRGB leds[NUM_LEDS]; uint8_t last_button_state; uint8_t shift_in_74hc165(); diff --git a/platformio.ini b/platformio.ini index 55a86ec..9ea2aee 100644 --- a/platformio.ini +++ b/platformio.ini @@ -8,7 +8,7 @@ framework = arduino lib_deps = adafruit/Adafruit TinyUSB Library@^2.0.0 - adafruit/Adafruit NeoPixel@^1.12.0 + fastled/FastLED@^3.9.0 build_flags = -DARDUINO_USB_MODE=1 diff --git a/src/led_stub.cpp b/src/led_stub.cpp index 07c72ae..5dde6d8 100644 --- a/src/led_stub.cpp +++ b/src/led_stub.cpp @@ -19,7 +19,7 @@ void DefaultLedStub::set_mux(PixelStompMux* mux) { } void DefaultLedStub::begin() { - Serial.println("[LED] Using WS2812C via PixelStomp MUX"); + Serial.println("[LED] Using WS2812C via PixelStomp MUX (FastLED)"); initialized = true; if (!mux_ptr) { @@ -30,13 +30,13 @@ void DefaultLedStub::begin() { Serial.println("[LED] Startup animation..."); uint32_t colors[] = { - 0xFF0000, // Red - 0x00FF00, // Green - 0x0000FF, // Blue - 0xFFFF00, // Yellow - 0xFF00FF, // Magenta - 0x00FFFF, // Cyan - 0xFFFFFF, // White + 0xFF0000, + 0x00FF00, + 0x0000FF, + 0xFFFF00, + 0xFF00FF, + 0x00FFFF, + 0xFFFFFF, }; int num_colors = sizeof(colors) / sizeof(colors[0]); @@ -51,7 +51,7 @@ void DefaultLedStub::begin() { } mux_ptr->show(); Serial.printf("[LED] Colour %d: R=%d G=%d B=%d\n", c, r, g, b); - delay(200); + delay(300); } clear_all(); @@ -71,15 +71,15 @@ void DefaultLedStub::set_led_state(uint8_t note, uint8_t channel, uint8_t veloci led_states[led_index].timestamp = millis(); if (velocity > 0) { - uint8_t brightness = map(velocity, 1, 127, 30, 255); + uint8_t brightness = map(velocity, 1, 127, 50, 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, + Serial.printf("[LED] Note %d -> LED %d Vel %d (%s)\n", + note, led_index, velocity, velocity > 0 ? "ON" : "OFF"); } else { Serial.printf("[LED] Out of range: %d (Note: %d)\n", led_index, note); diff --git a/src/pixel_stomp_mux.cpp b/src/pixel_stomp_mux.cpp index 95100ec..4c25043 100644 --- a/src/pixel_stomp_mux.cpp +++ b/src/pixel_stomp_mux.cpp @@ -5,7 +5,7 @@ PixelStompMux::PixelStompMux(uint8_t dat, uint8_t ld, uint8_t clk, uint8_t di) : pin_dat(dat), pin_ld(ld), pin_clk(clk), pin_di(di), - strip(nullptr), last_button_state(0) { + last_button_state(0) { } void PixelStompMux::begin() { @@ -16,15 +16,14 @@ void PixelStompMux::begin() { digitalWrite(pin_clk, LOW); digitalWrite(pin_ld, HIGH); - strip = new Adafruit_NeoPixel(NUM_LEDS, pin_dat, NEO_GRB + NEO_KHZ800); - strip->begin(); - strip->setBrightness(80); - strip->clear(); - strip->show(); + FastLED.addLeds(leds, NUM_LEDS); + FastLED.setBrightness(80); + fill_solid(leds, NUM_LEDS, CRGB::Black); + FastLED.show(); Serial.printf("[MUX] Init DAT=%d LD=%d CLK=%d DI=%d\n", pin_dat, pin_ld, pin_clk, pin_di); - Serial.printf("[MUX] 74HC165 x2 daisy-chain, WS2812C x%d LEDs\n", NUM_LEDS); + Serial.printf("[MUX] 74HC165 x2 daisy-chain, WS2812C x%d LEDs (FastLED)\n", NUM_LEDS); } uint8_t PixelStompMux::read_buttons() { @@ -52,24 +51,22 @@ bool PixelStompMux::is_button_pressed(uint8_t index) { } void PixelStompMux::set_led_color(uint8_t index, uint8_t r, uint8_t g, uint8_t b) { - if (index >= NUM_LEDS || !strip) return; - strip->setPixelColor(index, strip->Color(r, g, b)); + if (index >= NUM_LEDS) return; + leds[index] = CRGB(r, g, b); } void PixelStompMux::set_led_brightness(uint8_t brightness) { - if (strip) strip->setBrightness(brightness); + FastLED.setBrightness(brightness); } void PixelStompMux::clear_all() { - if (strip) { - strip->clear(); - strip->show(); - } + fill_solid(leds, NUM_LEDS, CRGB::Black); + FastLED.show(); Serial.println("[MUX] LEDs cleared"); } void PixelStompMux::show() { - if (strip) strip->show(); + FastLED.show(); } void PixelStompMux::dump() { @@ -108,15 +105,14 @@ void PixelStompMux::probe() { delayMicroseconds(5); } - Serial.println(" Testing NeoPixel DAT pin..."); - if (strip) { - strip->setPixelColor(0, strip->Color(255, 255, 255)); - strip->show(); - Serial.println(" Set pixel 0 to WHITE - check if it lights up"); - delay(1000); - strip->clear(); - strip->show(); - } + Serial.println(" Testing FastLED DAT pin..."); + fill_solid(leds, NUM_LEDS, CRGB::White); + FastLED.setBrightness(255); + FastLED.show(); + Serial.println(" All pixels WHITE (max brightness) - check if they light up"); + delay(2000); + fill_solid(leds, NUM_LEDS, CRGB::Black); + FastLED.show(); Serial.println("[MUX] === Probe Complete ==="); }