I am working on Jason Coons ESP8266 + FastLED web control using FastLED.

I am working on Jason Coons ESP8266 + FastLED web control using FastLED. I want to add a control to the web interface that allows the user to define the number of leds. In the sketch the NUM_LEDS is a #define. If I define the NUM_LEDS =1, can I add a variable that would add to the number of Leds using the web interface after adding a control in the web interface code?

In order to have a variable length, I use 2 values. One is the #define value, which is what must be used with the LEDS.addLeds<> statement.

The other is a variable (8 or 16 bit), that I use at runtime for actual the size of the array.

I have also implemented commands (but not for the web) that allow me to write that variable length to EEPROM memory. In my case, I use

#define MAX_LEDS 100 //Absolute maximum length

uint8_t NUM_LEDS = 60 // The actual length, which can change.

I’ll then define the strand with:

LEDS.addLeds<LED_TYPE, LED_DT, LED_CK, COLOR_ORDER >(leds, MAX_LEDS);

however, I’ll refer to the strand as . . for example:

fill_solid(leds,NUM_LEDS,CRGB(0,0,0)); // Fill 'em with black.

To save the strand length to EEPROM, I’ll add the eeprom library:

#include “EEPROM.h”

Then, I"ll define a memory location, i.e.

#define STRANDLEN 1

and then save it with:

EEPROM.write(STRANDLEN,NUM_LEDS);

and read that value with:

NUM_LEDS = EEPROM.read(STRANDLEN);

Reference:

https://github.com/atuline/FastLED-Demos/blob/master/seirlight/seirlight.ino

@Chris_Stock FastLED wasn’t really designed to have that be a variable value once the sketch is compiled. There are workarounds that a few have done, but it’s designed to be a fixed number defined at compile time.

If you search here and also the github issues you should find a few other variations on a solution to this, but the simplest work around is probably what Andrew said: Define a max value, and then have NUM_LEDS be a variable less then or equal to your max.