Skip to content

Commit 8b8cbbf

Browse files
committed
Fixed twinkle crash with > 255 LEDs. Updated to latest FastLED ESP32 parallel output. Added multiple strip setup. Added power management.
1 parent cd735b4 commit 8b8cbbf

File tree

4 files changed

+34
-13
lines changed

4 files changed

+34
-13
lines changed

data/js/app.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,12 @@ function postColor(name, value) {
431431
$.post(urlBase + "fieldValue?name=" + name + "&value=" + "&r=" + value.r + "&g=" + value.g + "&b=" + value.b, body, function(data) {
432432
$("#status").html("Set " + name + ": " + data);
433433
})
434-
.fail(function(textStatus, errorThrown) { $("#status").html("Fail: " + textStatus + " " + errorThrown); });
434+
.fail(
435+
function(jqXHR, textStatus, errorThrown) {
436+
console.error(textStatus);
437+
console.error(errorThrown);
438+
$("#status").html("Fail: " + textStatus + " " + errorThrown);
439+
});
435440
}
436441

437442
function delayPostColor(name, value) {

esp32-fastled-webserver.ino

+26-10
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ uint8_t currentPatternIndex = 0; // Index number of which pattern is current
4646
uint8_t gHue = 0; // rotating "base color" used by many of the patterns
4747

4848
uint8_t power = 1;
49-
uint8_t brightness = 64;
49+
uint8_t brightness = 8;
5050

5151
uint8_t speed = 30;
5252

@@ -69,13 +69,16 @@ unsigned long paletteTimeout = 0;
6969

7070
#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
7171

72-
#define DATA_PIN 12
72+
#define DATA_PIN 12 // pins tested so far on the Feather ESP32: 13, 12, 27, 33, 15, 32, 14, SCL
7373
//#define CLK_PIN 4
7474
#define LED_TYPE WS2812B
75-
#define COLOR_ORDER GRB
76-
#define NUM_LEDS 4 * 14
75+
#define COLOR_ORDER RGB
76+
#define NUM_STRIPS 8
77+
#define NUM_LEDS_PER_STRIP 100
78+
#define NUM_LEDS NUM_LEDS_PER_STRIP * NUM_STRIPS
7779
CRGB leds[NUM_LEDS];
7880

81+
#define MILLI_AMPS 4000 // IMPORTANT: set the max milli-Amps of your power supply (4A = 4000mA)
7982
#define FRAMES_PER_SECOND 120
8083

8184
// -- The core to run FastLED.show()
@@ -107,7 +110,6 @@ static TaskHandle_t userTaskHandle = 0;
107110
void FastLEDshowESP32()
108111
{
109112
if (userTaskHandle == 0) {
110-
const TickType_t xMaxBlockTime = pdMS_TO_TICKS( 200 );
111113
// -- Store the handle of the current task, so that the show task can
112114
// notify it when it's done
113115
userTaskHandle = xTaskGetCurrentTaskHandle();
@@ -116,6 +118,7 @@ void FastLEDshowESP32()
116118
xTaskNotifyGive(FastLEDshowTaskHandle);
117119

118120
// -- Wait to be notified that it's done
121+
const TickType_t xMaxBlockTime = pdMS_TO_TICKS( 200 );
119122
ulTaskNotifyTake(pdTRUE, xMaxBlockTime);
120123
userTaskHandle = 0;
121124
}
@@ -126,11 +129,10 @@ void FastLEDshowESP32()
126129
*/
127130
void FastLEDshowTask(void *pvParameters)
128131
{
129-
const TickType_t xMaxBlockTime = pdMS_TO_TICKS( 500 );
130132
// -- Run forever...
131133
for (;;) {
132134
// -- Wait for the trigger
133-
ulTaskNotifyTake(pdTRUE, xMaxBlockTime);
135+
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
134136

135137
// -- Do the show (synchronously)
136138
FastLED.show();
@@ -181,15 +183,29 @@ void setup() {
181183
SPIFFS.begin();
182184
listDir(SPIFFS, "/", 1);
183185

184-
loadFieldsFromEEPROM(fields, fieldCount);
186+
// loadFieldsFromEEPROM(fields, fieldCount);
185187

186188
setupWifi();
187189
setupWeb();
188190

189-
// tell FastLED about the LED strip configuration
190-
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
191+
// three-wire LEDs (WS2811, WS2812, NeoPixel)
192+
// FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
193+
194+
// four-wire LEDs (APA102, DotStar)
191195
//FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
192196

197+
// Parallel output: 13, 12, 27, 33, 15, 32, 14, SCL
198+
FastLED.addLeds<LED_TYPE, 13, COLOR_ORDER>(leds, 0, NUM_LEDS_PER_STRIP).setCorrection(TypicalLEDStrip);
199+
FastLED.addLeds<LED_TYPE, 12, COLOR_ORDER>(leds, NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP).setCorrection(TypicalLEDStrip);
200+
FastLED.addLeds<LED_TYPE, 27, COLOR_ORDER>(leds, 2 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP).setCorrection(TypicalLEDStrip);
201+
FastLED.addLeds<LED_TYPE, 33, COLOR_ORDER>(leds, 3 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP).setCorrection(TypicalLEDStrip);
202+
FastLED.addLeds<LED_TYPE, 15, COLOR_ORDER>(leds, 4 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP).setCorrection(TypicalLEDStrip);
203+
FastLED.addLeds<LED_TYPE, 32, COLOR_ORDER>(leds, 5 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP).setCorrection(TypicalLEDStrip);
204+
FastLED.addLeds<LED_TYPE, 14, COLOR_ORDER>(leds, 6 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP).setCorrection(TypicalLEDStrip);
205+
FastLED.addLeds<LED_TYPE, SCL, COLOR_ORDER>(leds, 7 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP).setCorrection(TypicalLEDStrip);
206+
207+
FastLED.setMaxPowerInVoltsAndMilliamps(5, MILLI_AMPS);
208+
193209
// set master brightness control
194210
FastLED.setBrightness(brightness);
195211

fields.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ String setSolidColor(uint8_t r, uint8_t g, uint8_t b)
158158
{
159159
solidColor = CRGB(r, g, b);
160160

161-
return String(solidColor.r) + "," + String(solidColor.g) + "," + String(solidColor.b);
161+
return "\"" + String(solidColor.r) + "," + String(solidColor.g) + "," + String(solidColor.b) + "\"";
162162
}
163163

164164
String setSolidColor(CRGB color) {

twinkleFox.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ void drawTwinkles()
194194

195195
uint8_t backgroundBrightness = bg.getAverageLight();
196196

197-
for(uint8_t i = 0; i < NUM_LEDS; i++) {
197+
for(uint16_t i = 0; i < NUM_LEDS; i++) {
198198
CRGB& pixel = leds[i];
199199

200200
PRNG16 = (uint16_t)(PRNG16 * 2053) + 1384; // next 'random' number

0 commit comments

Comments
 (0)