I've been working with the NeoPixels for years,

I’ve been working with the NeoPixels for years, and am just now getting into the FastLED library.

I’m building a simple blinky, with 4 buttons and 4 LEDs. If you press button 1, LED 1 lights up red… button 2, LED 2 lights up green… 3 is blue and 4 is yellow. If the buttons, LEDs, and color assignments are each an array, I should be able to have a super simple for loop to run it all (right?).

My arrays are:
CRGB leds[4];
uint8_t button[] = {10, 11, 12, 13}; //button pins

So, I’d like to do something like this:
colorVar[] = {“Red”, “Green”, “Blue”, “Yellow”};

There isn’t a variable type that can do this, right? Right now I have 3 more arrays, for red, green, and blue:
uint8_t red[] = {255, 0, 0, 255};
uint8_t green[] = {0, 255, 0, 255};
uint8_t blue[] = {0, 0, 255, 0};

and am setting the LEDs in the for loop like this:

leds[i].setRGB(red[i], green[i], blue[i]);

But I’d really like to have a single value, to do something like this:
leds[i] = CRGB::colorVar[i];
or
leds[i].setRGB(colorVar[i]);

I’d be happy using a single integer or web code (0xFF0000) if the words can’t be stored as variables, but not sure how. Can it be done simply?

THANK YOU

You can save the values as the CRGB data type. You can reference colors like CRGB::Red, CRGB::Violet, etc.

So;
leds[i] = CRGB::Red;

Is there a way to have the color be a variable stored in another array? Here’s my ideal code (below), but clearly the bColor[] array can’t be char, or else can’t use words.

Thanks!

#include <FastLED.h>
#define NUM_LEDS 4
#define DATA_PIN 9

CRGB leds[NUM_LEDS];
uint8_t button[] = {10, 11, 12, 13}; // buttons on pins 10-13
char bColor[] = {“Red”, “Green”, “Blue”, “Yellow”}; // char will not work for this

void setup() {
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
}

void loop() {
for (int b = 0; b < 4; b++){
if (digitalRead(button[b]) == HIGH){
leds[b] = CRGB::bColor[b];
}
else if (digitalRead(button[b]) == LOW){
leds[b] = CRGB::Black;
}
FastLED.show();
}
}

Use CRGB bColor[] = {CRGB::Red, CRGB::Green, CRGB::Blue, CRGB::Yellow}; (I’m assuming those basic colors are defined), then use them by leds[b]=bColor[b];

Working with HSV might simplify things.

Try changing this this:
colorVar[] = {“Red”, “Green”, “Blue”, “Yellow”};
to this:
uint8_t colorVar[] = {0, 96, 160, 64}; // Hue red, green, blue, yellow

and also update:
leds[b] = CRGB::bColor[b];
to:
leds[b] = CHSV(colorVar[b], 255, 255); // hue, saturation, value

More info on FastLED HSV:

Excellent suggestions – thank you! I’m loving this library.