If I wanted to write an all encompassing function that passed a string value

If I wanted to write an all encompassing function that passed a string value for the color name to fill_solids, how could I got about doing that? This doesn’t work:

void runColor(String color) {
if (currentMillis - previousMillis >= 200) {
previousMillis = currentMillis;
fill_solid(leds, NUM_LEDS, CRGB::color); //
FastLED.show();
}
}

Your function could take CRGB color instead of String color. The predefined colors list aren’t strings, they’re just enums for the color values: https://github.com/FastLED/FastLED/wiki/Pixel-reference#predefined-colors-list

https://github.com/FastLED/FastLED/blob/03d12093a92ee2b64fabb03412aa0c3e4f6384dd/pixeltypes.h#L590

So CRGB::Red is just a shortcut for 0xFF0000 or { 255, 0, 0 }, CRGB::Green is 0x00FF00 or { 0, 255, 0 }, etc.

In your example, where would the color name String come from? What would be calling this function? Are you wanting to pass these over Serial, Wi-Fi, etc?

At some point, yes, I’ll be passing values either via wifi or bluetooth/serial. For the time being, I’m using a state machine switch case in the Loop, calling the function with various colors amidst other patterns. I’m looking to keep the code as svelte as possible for my own sanity.

So, for example, I’ll have one case statement that calls runColor(FireBrick); and another that calls runColor(DodgerBlue);

Might this work:

void runColor(CRGB color){
if (currentMillis - previousMillis >= 200) {
previousMillis = currentMillis;
fill_solid(leds, NUM_LEDS, CRGB::color); //
FastLED.show();
}
}

runColor(FireBrick);

I think you’re close. I think it should be:

fill_solid(leds, NUM_LEDS, color);

and:

runColor(CRGB::FireBrick);

I’ll give it a whirl tonight. Thanks!

Here’s what worked:

runColor(“DodgerBlue”);

void runColor(CRGB color) {
if (currentMillis - previousMillis >= 200) {
previousMillis = currentMillis;
fill_solid(leds, NUM_LEDS, color); //
FastLED.show();
}
}

I spoke too soon. You were right Jason. Gotta use the CRGB as a variable when calling the function.