I'm having a problem using setting colors when using CRGB set with Arduino here's

I’m having a problem using setting colors when using CRGB set with Arduino here’s my code:

#define NUM_LEDS 36 // sets the number of LEDS
#define DATA_PIN 3 // defines the data pin
#define BRIGHTNESS 50

int flashDelay = 400; // defines how long to wait between flashes

CRGB rawleds[NUM_LEDS];
CRGBSet leds(rawleds, NUM_LEDS);
CRGBSet leds1(leds(0,11));
CRGBSet leds2(leds(12,23));
CRGBSet leds3(leds(24,36));

struct CRGB * ledsarray[] = {leds1, leds2, leds3};

void setup() {
Serial.begin(9600);
// sets up the library for WS2812B type LEDs on DATA_PIN with Green, Red, Blue color order
// on the leds[] array containing NUM_LEDS LEDs
delay (2000); // delay for safety
LEDS.addLeds<WS2812B,DATA_PIN,GRB>(leds, NUM_LEDS);
LEDS.setBrightness(BRIGHTNESS); // sets brightness of LEDs to previously defined BRIGHTNESS
}
void loop() {
for (int x = 0; x < 3; x++)
{

ledsarray[x]=CRGB::Blue;
Serial.println(x);
FastLED.show();
delay (flashDelay);
ledsarray[x]=CRGB::Black;
FastLED.show();
delay (flashDelay);
}
/*fill_solid (ledsarray[1],11, CRGB::Red);
FastLED.show();
delay (flashDelay);
fill_solid( ledsarray[1], 11, CRGB::Black);
FastLED.show();
delay (flashDelay);
fill_solid (ledsarray[2], 11, CRGB::Purple);
FastLED.show();
delay (flashDelay);
fill_solid (ledsarray[2], 11, CHSV(0,0,0));
FastLED.show();
delay (flashDelay);
/
}
The compiler gives me a "cannot convert ‘CRGB::HTMLColorCode’ to 'CRGB
’ in assignment" error. Currently, the only way I can use CRGBset is by using fill_solid() (the commented out code works fine). Assigning a color to a single LED works when using leds(x)=CRGB(255, 0,0) or CRGB::Red, it’s only when using CRGBset when it becomes a problem.

Any help?

Try updating the line:
CRGB rawleds[NUM_LEDS];
To:
CRGBArray<NUM_LEDS> leds;
And I think then remove the next line.

Here’s an example:

@Ken_Goldstein - Your code is trying to set one led to a color. In order to do that when using an array of arrays, you need the following:

ledsarray[x][y]=CRGB::Blue;

where x is the array number and y is the pixel number in ledsarray[x]. You are missing [y].

if I change one of the lines of your code to:

ledsarray[x][1]=CRGB::Blue;

and do the same for the other lines assigning colors this way, then it compiled assuming you have #include “FastLED.h” at the top of your sketch.

If you want to make the whole array a certain color, use:

fill_solid(ledsarray[x], 11, CRGB::Green);

where you or your code puts in a number for x.

See my sketches in Gist that cover this topic at:

and

Also see :

that covers this topic, too.

@Ken_White1 Thanks, that was the problem. Actually, I already downloaded your sketches for examples that work, so I could learn from them. But I couldn’t understand how the functions worked, such as why I needed a multidimensional array. Your explanation to my question helped greatly. Unfortunately, since the project I’m working on (lettered sign) has a different number of LEDs for each set it looks like I won’t be able to use a simple loop to deal with them as I can’t reference all the LEDs in each set without referring to the total number in each one, which was my initial plan. But, I’ll make do.

@Ken_Goldstein - Yes, you can deal with different size arrays in a loop or in code where you need an upper limit set to the size of the array. See my recent post on my CD77_police_lights Fun on Rings. Look at the Police_Lights.h code in :

You will see how to use size of an array function to set up various upper limits with different sizes of arrays to do what you want to do.

It uses:

#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))

If you have any problems setting it up then please let me know so that I can help you with that.

@Ken_White Actually, just figured out the different size set problem, I’m using an array with the different sizes in it and referencing it with the same variable e.g. fill_solid (ledsarray [x], Lsize[x], CRGB:: Red);