My application requires that I re-define the number of LEDs after I've compiled and

My application requires that I re-define the number of LEDs after I’ve compiled and uploaded the code to the Arduino Uno. At present, the Fast LED library seems to require you to define the number of LEDs with a “define” statement:

(example) #define NUM_LEDS 484

However, because the WS2811 LEDs operate in series, the frame rate is set by the number of LEDs. I need to be able to change the frame rate on the fly by effectively decreasing the number of LEDs in the #define statement … but I don’t see anyway to do this while the Arduino is running. Does anyone know how to do this?

Thanks in advance for your help.

As I recall . . . . I defined the maximum number of LED’s with:

#define MAX_LEDS 484 // or whatever

and used that definition for the strand.

I then used a variable called:

uint16_t NUM_LEDS; // for the actual strand

I also had a routine that allowed me to press an IR button to increase or decrease the value of NUM_LEDS and to then save that to Flash.

That should all be in my seirlight.ino demo at:

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

Disclaimer: I use Arduino Nano, and if I’m using an IR library, I need to use APA102’'s due to ‘FastLED interrupt issues’.

Thanks Andrew for your help. Are you certain that the frame rate is affected by changing NUM_LEDS as opposed to MAX_LEDS?

@Donald_Wile That, I haven’t tested, especially since I don’t use WS2812’s in this arrangement.

I haven’t tried this myself, and I’m not at home to test, but it might be possible to dynamically allocate the LED array (using new) and maintaining a global variable with the current LED length.

When you change the number of LEDs, you’d delete the array and create a new one with the desired length, update the global variable and call FastLED.addLeds() with the new array and length.

The main uncertainty I have is in the call to addLeds(), as I don’t know exactly what that’s doing behind the scenes. It could work fine, it could crash, or it could cause a memory leak. If I have time, I’ll give it a try later today.