Setting CRGB:: to text Variable

zColor[1]="AliceBlue";
zColor[2]="Amethyst";
zColor[3]="AntiqueWhite";
zColor[4]="Aqua";
zColor[5]="Aquamarine";
zColor[6]="Azure";
.
.
.
zColor[147]="Yellow";
zColor[148]="YellowGreen";
zColor[149]="FairyLight";
zColor[150]="FairyLightNCC";

// I imagine by now you know where I'm going with this..

for(int x = 1; x < 151; x++)
{

leds[ x ] = CRGB:: zColor[ x ]

FastLED.show();

delay(100);

}

But try as I might, I cannot figure a way for it to evaluate zColor[] as it's text value instead of it's variable name. Seems like in VB you'd do something like eval(zColor[]) or some such.

Can someone give me a clue here?

-BrianDP
Stuck in Led Land...

In C/C++, once the program is compiled, all notion of symbolic names in the programs go out the window. You will not get an automatic conversion between the text name and the symbolic name.

If what you are trying to do is set up a pattern of colours in the array, then use the number itself, something like:

zColor[1]=CRGB::AliceBlue;
zColor[2]=CRGB::Amethyst;
zColor[3]=CRGB::AntiqueWhite;

Okay. I guess what I was looking for just can't be done. Seems like an awful limitation though. I don't understand the finer points of compilers, and the like but what seems like a snap in other languages I've programmed in, in C++, I guess it just doesn't happen!

I do see what you're saying that I could use as a get-around. Just assign the CRGB stuff at the top instead of trying to feed it as an array, and assigning it that way. Just do it once at the top and it'd be done.

Thanks for your help.

-Brian

Seems like an awful limitation though.

The limitation is only your imagination, and perhaps a misconception of what you are actually doing when you write a program.

Seems like in VB you'd do something like eval(zColor[]) or some such.

The eval function can only ever be used in interpreted languages not compiled languages irrespective of the language you are programming in.

but what seems like a snap in other languages I've programmed in

So you have probably not programmed in a compiled language before.

The real root of your problem is that you are using names for the colours and not numbers.

Also, I just noticed you are using array indices from 1..MAX. In C/C++ array indices start at 0 and go to MAX-1 for a declaration like array[MAX]. As there is no checking for your boundary conditions you may end up accessing/changing memory outside your array if not used correctly.

Another difference between C/C++ and VB that will cause a lot of head scratching bugs if you don't know.

Could you make a table that would make a word to equal the number of the color, ie" 255 = "Blue", 16711680 = "Red", 32768 = "Green"

jimr1947:
Could you make a table that would make a word to equal the number of the color, ie" 255 = "Blue", 16711680 = "Red", 32768 = "Green"

The FastLED library already does something similar in the pixeltypes.h file, equating the color name to hexidecimal value for the color (each color is a 24-bit number, with 8 bits for each of the three colors red, green, and blue). See reply #1 for the syntax to use those predefined names. There is nothing in FastLED that equates the ascii text for a color name to the color value.

If you wanted to take the color name from a user input, and equate that to the actual color value, you could set up a table with the ascii text for each color name, and the RGB value associated with that name, then search through the table comparing the text until you found a match.

For the OP, you can define the array as follows:

CRGB zColor[] = {
  CRGB::AliceBlue,
  CRGB::Amethyst,
  CRGB::AntiqueWhite,
  CRGB::Aqua,
  CRGB::Aquamarine,
  CRGB::Azure,
  //
  //
  //
  CRGB::Yellow,
  CRGB::YellowGreen,
  CRGB::FairyLight,
  CRGB::FairyLightNCC
};

Then in loop() set the pixel colors with

  for (int x = 0; x < sizeof(zColor)/sizeof(zColor[0]); x++) 
  // sizeof(zColor)/sizeof(zColor[0]) gives the number of elements in the zColor array
  {
    leds[x]  =  zColor[x];
  }