Trying to set a color from user input for different patterns,

Trying to set a color from user input for different patterns, I want the user to input a color to cycle, is there a way to set leds[i] = CRGB::color from user input ? say I want blue it would become CRGB::Blue so forth, cant seem to find a way to do it.

if (txtMsg == “swipe”) {
Serial.print(“What color?”);
color = Serial.readString();
CRGB colorfix=color;
while (clen != 0)
{ for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB::color;;
// clear this led for the next time around the loop
leds[i] = CRGB::Black;

In past i would set up desired animations, then print out a table of menu table with last item “what selection”… do nothing while waiting on input… from input x do switch case on x to desired animation when animation complete reset x to zero and reprint menu and wait dor next x input… simpleton way but works for fast build…

Color could also be sent as:
RGB: (255,0,0), would need to send three values.
HSV: (0,255,255), would only need to send the hue (assuming saturation and value are 255),
HEX: 0xFF0000

I was just seeing if there was a shortcut to make more compact code to get user input for the CRGB::“value”

How are you wanting to send/receive the color, ie. in what format?

As others have mentioned, I’d probably just input a hue value, and use this chart:

@marmil bluetooth serial. I am trying to make it easy for a user to say I want this pattern, but also this color. I can only see a use for it for two patterns right now but I was jjust interested if it was possible.

Ease of use for the user has to do with the UI provided to them. It could be a box they type a number into, slider(s), color wheel, specific list of colors to pick from, etc, etc. That can be totally different from how you choose to format and send the data which can all be under the hood to the user.
Yes, it’s serial data, but what I was asking is are you wanting to send the color data as three bytes (either RGB or HSV), an int made from combining three bytes, a single byte representing just a Hue, a Hex value, an actual text string such as “Blue”, a code number or letter for a predefined specific color choice, etc.?

@marmil actual string. I am running it through just free BLE serial terminals that users will download. an iOS dev license is 99$ a year. I’d rather just have the user input values over terminal so I don’t have to develop an app for iOS, I have built an app for Android for fastled but using bluetooth serial terminals makes it easier for iOS and Android users ( as well as saving me money from dev licenses)

IMO, a text string seems like the more difficult way to send a color choice since the user must know the color names and it’s case sensitive. You’ll also have to deal with different length strings (which isn’t necessarily difficult, but has to be considered). Sending a byte or three comma separated bytes just seems like it would simplify things a lot. :stuck_out_tongue:

Ok, so if it’s to be text, and the user sends “Blue”, your question is how to get that to be CRGB::Blue for FastLED to be able to use it?

@marmil yeah, I ended up just doing hex values, and I already had a function to change the first letter to capitol after making it all lowercase. there doesnt seem to be a way to make it take the user value and then make it CRGB::“uservalue string”
I just made a colorhexfix function that uses if statements to check for blue red green… then convert to hex and it works but I was hoping there was a simpler method for compactness

I guess you could make a switch case setup that uses your read text string to set the correct color.

switch (readText) {
case Blue:
color = CRGB(0,0,255);
case Red:
color = CRGB::Red;

Not exactly compact depending on how many colors in text form you actually want to accept.
Are you really tight on programming space?

@marmil thats what I did in its own function. Was just trying to see if there was a way to compact them .