I’d like to be able to set the number of pixels in a string at run time. I understand this is usually done at compile time for speed reasons, but I wonder if there is an alternate method.
I’m happy for it to only be set once before the string is initialised, but as the output hardware is modular (pluggable pixels), having it hard coded into the software is not possible.
The trick seems to be that you need to save a reference to the controller that is created with addLeds(), then later you can call setLeds() on it to change the number of LEDs
That’s my understanding as well. We keep a count of the maximum number of LEDs that we’ve seen control data for, and expand the output range to match.
It can all be in your main program. The only thing to watch is that you need to define the LED data structure:
struct CRGB leds[MAX_LEDS]; // Space to hold the current LED data
with the maximum number of LEDs that might be controlled, since it needs to have space to store the color values. It’s up to you to make sure you don’t set setLeds() with a number that’s larger than the storage space can accommodate.