QUESTION: How to control multiple strips of different length?

QUESTION: How to control multiple strips of different length?

Hi all! Glad to find an active group while I’m learning how to program LEDs! My first hurdle is that I’m trying to use multiple Neopixel rings of different sizes. I thought just recalling the length and name of CRGB objects would be easiest, but I couldn’t figure out how to do that. So, I setup the code as follows:

#include “FastLED.h”
#define NUM_RINGS 3
CRGB smallRing[12];
CRGB medRing[16];
CRGB largeRing[24];

int ringSizes[] = {12, 16, 24};
char* ringNames[] = {“smallRing”, “medRing”, “largeRing”};

void setup() {
delay(3000); // 3 second delay for recovery

FastLED.addLeds<NEOPIXEL, 3>(smallRing, 12);
FastLED.addLeds<NEOPIXEL, 9>(medRing, 16);
FastLED.addLeds<NEOPIXEL, 6>(largeRing, 24);

// set master brightness control

void loop() {
// This outer loop will go over each ring, one at a time
for(int x = 0; x < NUM_RINGS; x++) {
int NUM_LEDS = ringSizes[x];

// This inner loop will go over each led in the current ring, one at a time
for(int i = 0; i < NUM_LEDS; i++) {
ringNames[x] = CRGB::Green;;
ringNames[x] = CRGB::Black;

error: cannot convert ‘CRGB::HTMLColorCode’ to ‘char*’ in assignment

The error maps to the 2nd to last line of code (when executing ringNames[x]). After some floundering on StackOverflow I think it’s because C is not a dynamic language, so basically I can’t use a string as a variable name. Poof, mind blown! After learning to code in Python I wasn’t aware of the concept of reflection.

Can anyone suggest how to recall the length and name of CRGB objects? Or a better way of going about this in general?

ringNames is just an array of strings - that has no meaning compared to variables. What you want instead is something like:

CRGB *rings[] = {smallRing, medRing, largeRing};

then you can say

rings[x][i] = CRGB::Green;

(roughly, give or take)

Awesome, thank you @Daniel_Garcia ! Updated my question to reflect my misconception of reflections. Can I potentially use “sizeof(rings[x])” instead of making the ringSizes array?

Not reliably, no. You might be able to use:

int ringSizes[3] = {sizeof(smallRing)/sizeof(CRGB), sizeof(medRing)/sizeof(CRGB),sizeof(largeRing)/sizeof(CRGB)};

but i’m not 100% sure that will work.

And it’s way longer, yikes! Thanks for your help!