Hello to the FastLED community! I am brand new with learning Arduino and I

Hello to the FastLED community!

I am brand new with learning Arduino and I am teaching myself how to use the program as well as program my own light strip. Sorry if the following question is easy to answer, but I have been having trouble with arrays

So say I want the first 3 leds in my strip to turn on, but I do not want to write

leds[0].setRGB(255,0,0); FastLED.show();
leds[1].setRGB(255,0,0); FastLED.show();
leds[2].setRGB(255,0,0); FastLED.show();

So I tried to write the code like this instead

leds[0,1,2].setRGB(255,0,0); FastLED.show();
but only the third LED turns on

I have tried defining some leds into an array as follows

//writing variables
int start[3] = {0,1,2};

//run the setup

leds[start].setRGB(255,0,0); FastLED.show();

but I get the following error when verifying the code

“invalid types ‘CRGB [450][int [3]]’ for array subscript”

My question is, how can I make multiple LEDs turn on with one command, either through defining an array or by assigning them in the call to “leds[0,1,2,…]”, without having to write “leds[0]…leds[1]…leds[2]…” multiple times?

Thanks again, sorry if there is an easy answer, but as I said, I am new to Arduino as well as this program

You may want to look into a general programming introduction. Traditionally, you’d make a loop if you have several items in an array you want to set. For example:

for (int i=0; i<3; i++) {
leds[i] = CRGB(255,0,0);
}
FastLED.show();

So this would run 3 times for values of i being 0, then 1, then 2. Note that you don’t have to call the show() command after every change in the leds[] array, it suffices to do that once per loop (if even - you often can get away with doing it far less than that).

Have a look here for an overview of all the things the programming language can do: https://www.arduino.cc/en/Reference/HomePage

If you have questions just ask, all of us got started at some point, almost nobody is born knowing it all.

You will use for loops a lot for all kinds of things. :slight_smile:

If you just what to set a couple of pixels you could also do something like this:

// This will set the first three pixels to red
leds[0] = leds[1] = leds[2] = CRGB(255,0,0);

FastLED.show(); // Display the updates

Mr Kriegsman has a sketch for running two different effects on the same strip and – as a result – sections off the strip with code. You can find it here…

If you are using CRGBArray as mentioned here: https://github.com/FastLED/FastLED/wiki/RGBSet-Reference
You can say leds(0,2) = CRGB(255,0,0); This will set the first 3 LEDs to red.

Thanks all! I appreciate the help, especially not having to call the FastLED.show after each change. I assumed I had to do it after each change. I guess I should have specified, but I had already made a “for” loop to update the LED’s and make them back and forth, I was just trying to understand how to turn more than one on at a time. I realize my mistake in calling “leds[0,1,2]” as Arduino would only read the last value, as I should do “leds[0,2]” instead to get it to read 0,1,2.

Thanks Mark for specifying that I can call “leds[0] = leds[1] = …” and Brian for the leds[0,2] code