FastLED dynamic pins and LED count

Hey, I wanted to make my code very dynamic so that I can modify everything by just modifying a define or const value. I'm coding in C++ and this was my desired code if it would work:

// ...
#define NUM_STRIPS 2
const LED_STRIP_PINS[NUM_STRIPS] = {38, 39};
const LEDS_PER_STRIP[NUM_STRIPS] = {300, 300};

void setup() {
  // ...
  int tmp = 0;
  for(int i = 0; i < NUM_STRIPS; i++) {
    pinMode(LED_STRIP_PINS[i], OUTPUT);
    FastLED.addLeds<NEOPIXEL, LED_STRIP_PINS[i]>(leds + tmp, LEDS_PER_STRIP[i]);
    tmp += LEDS_PER_STRIP[i];
  }
}
// ...

The problem of course is that LED_STRIP_PINS[i] can't be used in the context of an template, because i is not constant. Is there anything I could do to fix this? Yes, I know I just could make a define for every strip and make a new "FastLED.addLeds<...>(...)" for every strip, but just out of curiosity - is it somehow possible?

Welcome to the forum

Why not declare the number of strips and number of LEDs then use a #define or variable to limit how many of each are used ?

Without rewriting FastLED library - I think no. Template arguments MUST be known at compile time.
Try to look for another led library, that not uses a template.

1 Like

The Adafruit_Neopixel library should work, it allows changing output pins at runtime, while FastLED likes to hard code the output pin at compile time.

1 Like