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
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <Adafruit_NeoPixel.h>
|
#include <FastLED.h>
|
||||||
|
|
||||||
class PixelStompMux {
|
class PixelStompMux {
|
||||||
public:
|
public:
|
||||||
@@ -29,8 +29,7 @@ private:
|
|||||||
uint8_t pin_clk;
|
uint8_t pin_clk;
|
||||||
uint8_t pin_di;
|
uint8_t pin_di;
|
||||||
|
|
||||||
Adafruit_NeoPixel* strip;
|
CRGB leds[NUM_LEDS];
|
||||||
|
|
||||||
uint8_t last_button_state;
|
uint8_t last_button_state;
|
||||||
|
|
||||||
uint8_t shift_in_74hc165();
|
uint8_t shift_in_74hc165();
|
||||||
|
|||||||
+1
-1
@@ -8,7 +8,7 @@ framework = arduino
|
|||||||
|
|
||||||
lib_deps =
|
lib_deps =
|
||||||
adafruit/Adafruit TinyUSB Library@^2.0.0
|
adafruit/Adafruit TinyUSB Library@^2.0.0
|
||||||
adafruit/Adafruit NeoPixel@^1.12.0
|
fastled/FastLED@^3.9.0
|
||||||
|
|
||||||
build_flags =
|
build_flags =
|
||||||
-DARDUINO_USB_MODE=1
|
-DARDUINO_USB_MODE=1
|
||||||
|
|||||||
+12
-12
@@ -19,7 +19,7 @@ void DefaultLedStub::set_mux(PixelStompMux* mux) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DefaultLedStub::begin() {
|
void DefaultLedStub::begin() {
|
||||||
Serial.println("[LED] Using WS2812C via PixelStomp MUX");
|
Serial.println("[LED] Using WS2812C via PixelStomp MUX (FastLED)");
|
||||||
initialized = true;
|
initialized = true;
|
||||||
|
|
||||||
if (!mux_ptr) {
|
if (!mux_ptr) {
|
||||||
@@ -30,13 +30,13 @@ void DefaultLedStub::begin() {
|
|||||||
Serial.println("[LED] Startup animation...");
|
Serial.println("[LED] Startup animation...");
|
||||||
|
|
||||||
uint32_t colors[] = {
|
uint32_t colors[] = {
|
||||||
0xFF0000, // Red
|
0xFF0000,
|
||||||
0x00FF00, // Green
|
0x00FF00,
|
||||||
0x0000FF, // Blue
|
0x0000FF,
|
||||||
0xFFFF00, // Yellow
|
0xFFFF00,
|
||||||
0xFF00FF, // Magenta
|
0xFF00FF,
|
||||||
0x00FFFF, // Cyan
|
0x00FFFF,
|
||||||
0xFFFFFF, // White
|
0xFFFFFF,
|
||||||
};
|
};
|
||||||
int num_colors = sizeof(colors) / sizeof(colors[0]);
|
int num_colors = sizeof(colors) / sizeof(colors[0]);
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ void DefaultLedStub::begin() {
|
|||||||
}
|
}
|
||||||
mux_ptr->show();
|
mux_ptr->show();
|
||||||
Serial.printf("[LED] Colour %d: R=%d G=%d B=%d\n", c, r, g, b);
|
Serial.printf("[LED] Colour %d: R=%d G=%d B=%d\n", c, r, g, b);
|
||||||
delay(200);
|
delay(300);
|
||||||
}
|
}
|
||||||
|
|
||||||
clear_all();
|
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();
|
led_states[led_index].timestamp = millis();
|
||||||
|
|
||||||
if (velocity > 0) {
|
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);
|
mux_ptr->set_led_color(led_index, brightness, brightness, brightness);
|
||||||
} else {
|
} else {
|
||||||
mux_ptr->set_led_color(led_index, 0, 0, 0);
|
mux_ptr->set_led_color(led_index, 0, 0, 0);
|
||||||
}
|
}
|
||||||
mux_ptr->show();
|
mux_ptr->show();
|
||||||
|
|
||||||
Serial.printf("[LED] Note %d -> LED %d Ch %d Vel %d (%s)\n",
|
Serial.printf("[LED] Note %d -> LED %d Vel %d (%s)\n",
|
||||||
note, led_index, channel, velocity,
|
note, led_index, velocity,
|
||||||
velocity > 0 ? "ON" : "OFF");
|
velocity > 0 ? "ON" : "OFF");
|
||||||
} else {
|
} else {
|
||||||
Serial.printf("[LED] Out of range: %d (Note: %d)\n", led_index, note);
|
Serial.printf("[LED] Out of range: %d (Note: %d)\n", led_index, note);
|
||||||
|
|||||||
+20
-24
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
PixelStompMux::PixelStompMux(uint8_t dat, uint8_t ld, uint8_t clk, uint8_t di)
|
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),
|
: 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() {
|
void PixelStompMux::begin() {
|
||||||
@@ -16,15 +16,14 @@ void PixelStompMux::begin() {
|
|||||||
digitalWrite(pin_clk, LOW);
|
digitalWrite(pin_clk, LOW);
|
||||||
digitalWrite(pin_ld, HIGH);
|
digitalWrite(pin_ld, HIGH);
|
||||||
|
|
||||||
strip = new Adafruit_NeoPixel(NUM_LEDS, pin_dat, NEO_GRB + NEO_KHZ800);
|
FastLED.addLeds<WS2812, 9, GRB>(leds, NUM_LEDS);
|
||||||
strip->begin();
|
FastLED.setBrightness(80);
|
||||||
strip->setBrightness(80);
|
fill_solid(leds, NUM_LEDS, CRGB::Black);
|
||||||
strip->clear();
|
FastLED.show();
|
||||||
strip->show();
|
|
||||||
|
|
||||||
Serial.printf("[MUX] Init DAT=%d LD=%d CLK=%d DI=%d\n",
|
Serial.printf("[MUX] Init DAT=%d LD=%d CLK=%d DI=%d\n",
|
||||||
pin_dat, pin_ld, pin_clk, pin_di);
|
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() {
|
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) {
|
void PixelStompMux::set_led_color(uint8_t index, uint8_t r, uint8_t g, uint8_t b) {
|
||||||
if (index >= NUM_LEDS || !strip) return;
|
if (index >= NUM_LEDS) return;
|
||||||
strip->setPixelColor(index, strip->Color(r, g, b));
|
leds[index] = CRGB(r, g, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelStompMux::set_led_brightness(uint8_t brightness) {
|
void PixelStompMux::set_led_brightness(uint8_t brightness) {
|
||||||
if (strip) strip->setBrightness(brightness);
|
FastLED.setBrightness(brightness);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelStompMux::clear_all() {
|
void PixelStompMux::clear_all() {
|
||||||
if (strip) {
|
fill_solid(leds, NUM_LEDS, CRGB::Black);
|
||||||
strip->clear();
|
FastLED.show();
|
||||||
strip->show();
|
|
||||||
}
|
|
||||||
Serial.println("[MUX] LEDs cleared");
|
Serial.println("[MUX] LEDs cleared");
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelStompMux::show() {
|
void PixelStompMux::show() {
|
||||||
if (strip) strip->show();
|
FastLED.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelStompMux::dump() {
|
void PixelStompMux::dump() {
|
||||||
@@ -108,15 +105,14 @@ void PixelStompMux::probe() {
|
|||||||
delayMicroseconds(5);
|
delayMicroseconds(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.println(" Testing NeoPixel DAT pin...");
|
Serial.println(" Testing FastLED DAT pin...");
|
||||||
if (strip) {
|
fill_solid(leds, NUM_LEDS, CRGB::White);
|
||||||
strip->setPixelColor(0, strip->Color(255, 255, 255));
|
FastLED.setBrightness(255);
|
||||||
strip->show();
|
FastLED.show();
|
||||||
Serial.println(" Set pixel 0 to WHITE - check if it lights up");
|
Serial.println(" All pixels WHITE (max brightness) - check if they light up");
|
||||||
delay(1000);
|
delay(2000);
|
||||||
strip->clear();
|
fill_solid(leds, NUM_LEDS, CRGB::Black);
|
||||||
strip->show();
|
FastLED.show();
|
||||||
}
|
|
||||||
|
|
||||||
Serial.println("[MUX] === Probe Complete ===");
|
Serial.println("[MUX] === Probe Complete ===");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user