Hi folks - I need my FastLED codebase to work on multiple setups that each have a unique number of LEDs. Based on each unique device’s name/ID, I can figure out the # of LEDs in setup(), but I need that value sooner, in order to initialize the “leds” CRGB array in the global portion of the code.
I tried using std::vector which can be dynamically resized, but get compile errors on functions like addLeds and fill_solid because they expect an array, not a std::vector.
Any tips on how to accomplish this? I haven’t found a way to initialize a global variable inside of a (non-global) function. I’m using Particle Photon with WS2813 neopixels, in case that matters.
You might need to set the array to match the largest setup, then in your code use a variable instead of the NUM_LEDS constant. You will in effect be sending black of the non-existent LEDs, but this should not cause any issues
Yeah, that’s my current workaround. Was looking for something a bit more memory-efficient and “correct” but then again, I’ll need to be prepared for worst case scenario anyway so perhaps there is no harm in this approach.
So I reserve memory for 2000 LEDs per channel upfront, and then later when I call FastLED.addLeds, I will know how many LEDs the installation actually has (by calling a one-time configuration function at the beginning of loop), and I use that number in FastLED.addLeds().
It isn’t memory-optimized, but it works for the sizes of installations I’m doing now.