Is there a way to create an array of CRGBSets? For example,

Is there a way to create an array of CRGBSets? For example, I created a couple CRGBSets like so:

CRGBArray<NUM_LEDS> leds;
CRGBSet setOne = leds(0, 10);
CRGBSet setTwo = leds(11, 20);

I then want to create an array:

CRGBSet rgbSetArray[2];

When I do that without any initial assignment, I get the error: “candidate expects 1 argument, 0 provided
no matching function for call to ‘CPixelView::CPixelView()’”

If I do initial assignment like:

CRGBSet rgbSetArray[2] [ {setOne, setTwo};

reassignment (rgbSetArray[1] = setTwo) does not work correctly. rgbSetArray[1] is still setTwo after trying that.

Thanks for the help!

Try rgbSetArray[0] = setTwo
The first element of the array is [0] not [1]

@Dushyant_Ahuja doh that’s what I meant to say (that’s what happens after hours of work :D), but it’s still not working. Here’s my sample code:

CRGBArray<NUM_LEDS> leds;
CRGBSet setOne = leds(0, 9);
CRGBSet setTwo = leds(10, 19);
CRGBSet setThree = leds(20, 29);
CRGBSet toLight[2] = {setOne, setTwo};
CRGB color = CRGB::White;

void myFunc(){
toLight[0] = setThree;
for (int i=0; i < 2; i++){
toLight[i] = color;
}
FastLED.show();
}

setOne and setTwo are still being lit up though, while it should be setThree and setTwo.

@Joe_Meissler I don’t remember my C++ that well - but have you tried to create an array of pointers instead. That would probably be more efficient as well.

Also try fill_solid(toLight[i],2,color) instead of toLight[i] = color;

@Dushyant_Ahuja my knowledge of C++ is just hacking away on arduino projects. It took me too long to figure out how to create a single CRGBSet :smiley:

Thanks for the tip though. I’ll look into that tonight.

@Dushyant_Ahuja outside of the loop? If it’s inside, what is the “2” for?

@Joe_Meissler try the second suggestion

Inside the loop. The 2 is for two leds in the CRGBSets

Basically you cannot assign a colour to multiple leds using the = and need to use the fill_solid function instead.

@Dushyant_Ahuja same result :confused:

@Dushyant_Ahuja You can assign multiple leds with =. For instance,

setOne = CRGB::White;

works just fine. Here’s a line from the FastLED wiki:

for(int i = 0; i < NUM_LEDS-1; i++) { leds(i,i+1) = CRGB::Red; FastLED.delay(33); leds(i,i+1) = CRGB::Black; }

Try this

CRGBArray<NUM_LEDS> leds;
CRGBSet setOne = leds(0, 9);
CRGBSet setTwo = leds(10, 19);
CRGBSet setThree = leds(20, 29);
CRGBSet *toLight[2] = {&setOne, &setTwo};
CRGB color = CRGB::White;

void myFunc(){
toLight[0] = &setThree;
for (int i=0; i < 2; i++){
fill_solid(*toLight[i],2,color);
}
FastLED.show();
}

For that to work you would have to use toLight[i] (1,2)= color;

Anyways try the example I provided above.

Will do. Thanks for the help.

@Dushyant_Ahuja just gave your code a try. The array assignment works, but fill_solid(*toLight[i],2,color); only lights up 2 LEDs at a time. Having that number be dynamic would be tricky. However, *toLight[i] = color; works just fine. Thanks for all the help.

you can try sizeof(*toLight[i])/sizeof(*toLight[i][0]) instead of 2

@Joe_Meissler Take a look at these two examples:

and

I think they will provide you with the information that you are looking for.

@Ken_White works great, thanks for putting that together

I find this interesting, as this is something I was working on related to my project. I have to work with multiple led objects that are effectively diamond layouts (they are computer fans, mind you) and I needed to be able to address the fans individually and segments of each fan individually. As a result, I ended up with a multidimensional array of pointers to CRGBSets that I was able to set up in loops and can address in loops. This applies here too…

A short set of some examples:
//Global
CRGBSet *set[2];

//In setup()
set[0] = new CRGBSet( leds(0,10) );
set[1] = new CRGBSet( leds(11,20) );

//In place of any case of setOne(start,end)
//use set[0]>operator()(start,end)
set[0]>operator()(0,2) = CRGB::Green;
set[0]->operator()(3,5).fill_rainbow(hue++);

//In place of setTwo[n]
//use (*set[1])[n]
(*set[1])[3] = CRGB::Blue;

It works fine with multidimensional arrays of pointers too.