How to switch between arrays?

I am working on a project involving an APA102 LED strip, and I want to be able to change the colors based on an input. I have the RGB color values stored in an array, and then call upon values from the array to know what values to use. Here is my code.

if (ledOn == true)
  {
    ledStrip.startFrame();

    for(uint16_t i = 0; i < ledCount; i++)
    {
      ledStrip.sendColor(limeGreen[0], limeGreen[1], limeGreen[2]);
    }

    ledStrip.endFrame(ledCount);
  }
  else
  {
    ledStrip.startFrame();

    for(uint16_t i = 0; i < ledCount; i++)
    {
      ledStrip.sendColor(0, 0, 0);
    }

    ledStrip.endFrame(ledCount);  
  }

I want to be able to switch between the arrays that are inputting the value so that I can switch the color. Since all of the arrays have the same amount of contents, could I create a variable to put in place of the array name, and change the value of that? If not how could it change the input array?

Could you use a 2D array?

Either a 2D array:

byte Colors[][3] = {{255,255,255}, // White
{0, 0, 0}} // Black

or an array of pointers to arrays of 3 bytes. (This takes more room because there is a pointer to each color array)

byte *(Colors[3])[] = {White, Black, limeGreen, Purple...}

Not sort if my idea is what you are looking for, but….

I use a colour wheel to select colours. This is 4 bit colour, but you can make it any value you like.
Also from my experience to get nice colour, avoid using colours that include red, green and blue, as they are pastel and wishy washy, excluding when you want white.

With my code you now use this ;-

GetColour( your colour value here as a number or the pre named colours );
ledStrip.sendColor(myRed,myGreen, myBlue);

First define the colour wheel

#define BAM_RESOLUTION 4    // EG 4 bit colour = 15 variation of R, G & B (4096 colours)
const  int Size_CW = ((1 << BAM_RESOLUTION) - 1) * 6; //Number of steps in colour wheel. Why x 6, cos any more will give repeat colours.
// ***********  Colour Variables ***************
int Colour[Size_CW][3]; //Used to store colour for the cube in R, G and B = [3]
byte myRed, myGreen, myBlue; //Used to call colour from GetColour routine
int myColour = 0;// General purpose variable.

// These are standard colors which can be called by name when using the GetColour routine
//EG to get Cyan, GetColour(Cyan) will retun myRed, myGreen & myBlue for the colour Cyan = Red off, Green max, Blue max
#define Magenta  Size_CW / 6 -1
#define Red Size_CW / 3 -1
#define Yellow  Size_CW / 2 - 1
#define Green Size_CW / 1.5 -1
#define Cyan  Size_CW / 1.2 -1
#define Blue Size_CW -1

Then fill the colour wheel.

void setup() {
  FillColourWheel();//Fill colour wheel with array of colour - Call Colour [0 - Size_CW] [0=R,1=G,2=B] or GetColour[colour#]
}
void FillColourWheel() {
  myRed = 0;
  int phase = 0;
  byte I = 0;
  while (phase < Size_CW) {
    switch (I) {
      case 0:             //Fill ColourWheel from Blue to Magenta
        myRed++;
        myGreen = 0;
        myBlue = ((1 << BAM_RESOLUTION) - 1);
        break;
      case 1:             //Fill ColourWheel from Magenta to Red
        myRed = ((1 << BAM_RESOLUTION) - 1);
        myGreen = 0;
        myBlue--;
        break;
      case 2:             //Fill ColourWheel from Red To Yellow
        myRed = ((1 << BAM_RESOLUTION) - 1);
        myGreen++;
        myBlue = 0;
        break;
      case 3:             //Fill ColourWheel from Yellow to Green
        myRed--;
        myGreen = ((1 << BAM_RESOLUTION) - 1);
        myBlue = 0;
        break;
      case 4:             //Fill ColourWheel from Green to Cyan
        myRed = 0;
        myGreen = ((1 << BAM_RESOLUTION) - 1);
        myBlue++ ;
        break;
      case 5:             //Fill ColourWheel from Cyan to Blue
        myRed = 0;
        myGreen--;
        myBlue = ((1 << BAM_RESOLUTION) - 1);
        break;

    }
    Colour[phase][0] = myRed;
    Colour[phase][1] = myGreen;
    Colour[phase][2] = myBlue;
    if (++phase >= (1 + I) * ((1 << BAM_RESOLUTION) - 1))
      I++;
  }
}//********** End Fill Colour Wheel ********************

Now to select the colour you want.

GetColour( your colour value here);
ledStrip.sendColor(myRed,myGreen, myBlue);

The GetColour call. This make sure you are with in the range and returns the colour

//********** Get Colour and check it is within tolerance. ********************
void GetColour(int colour) {// Standard colours from colour wheel
  while (colour < 0) {              //If "colour" is a negative value
    colour += Size_CW;
  }
 while (colour >= Size_CW) {       //If "colour" is greater than Size of Colour Wheel.
    colour -= Size_CW;
  }
  myRed = Colour[colour][0];
  myGreen = Colour[colour][1];
  myBlue = Colour[colour][2];
}

attached is a representation of all colour for this code.

While all of the solutions could work - I think :) - I think the array of pointers best suits my needs. Could you please explain how it works a little bit further in depth, I don't completely understand.

1204NeRd: While all of the solutions could work - I think :) - I think the array of pointers best suits my needs. Could you please explain how it works a little bit further in depth, I don't completely understand.

Arrays and pointers can be used almost interchangeably. Here is an example that defines three-element byte arrays for some of the named HTML colors, defines an array of pointers to those named colors, and defines an 'enum' that assigns number values to the names so they can be used to index into the array of pointers.

const byte CYAN_RGB[3] = {0, 255, 255};
const byte LIGHTCYAN_RGB[3] = {224, 255, 255};
const byte PALETURQUOISE_RGB[3] = {175, 238, 238};
const byte AQUAMARINE_RGB[3] = {127, 255, 212};
const byte TURQUOISE_RGB[3] = {64, 224, 208};
const byte MEDIUMTURQUOISE_RGB[3] = {72, 209, 204};
const byte DARKTURQUOISE_RGB[3] = {0, 206, 209};
const byte CADETBLUE_RGB[3] = {95, 158, 160};
const byte STEELBLUE_RGB[3] = {70, 130, 180};
const byte LIGHTSTEELBLUE_RGB[3] = {176, 196, 222};
const byte POWDERBLUE_RGB[3] = {176, 224, 230};
const byte LIGHTBLUE_RGB[3] = {173, 216, 230};
const byte SKYBLUE_RGB[3] = {135, 206, 235};
const byte LIGHTSKYBLUE_RGB[3] = {135, 206, 250};
const byte DEEPSKYBLUE_RGB[3] = {0, 191, 255};
const byte DODGERBLUE_RGB[3] = {30, 144, 255};
const byte CORNFLOWERBLUE_RGB[3] = {100, 149, 237};
// const byte MEDIUMSLATEBLUE_RGB[3] = {123, 104, 238};
const byte ROYALBLUE_RGB[3] = {65, 105, 225};
const byte BLUE_RGB[3] = {0, 0, 255};
const byte MEDIUMBLUE_RGB[3] = {0, 0, 205};
const byte DARKBLUE_RGB[3] = {0, 0, 139};
const byte NAVY_RGB[3] = {0, 0, 128};
const byte MIDNIGHTBLUE_RGB[3] = {25, 25, 112};
const byte CORNSILK_RGB[3] = {255, 248, 220};
const byte BLANCHEDALMOND_RGB[3] = {255, 235, 205};
const byte BISQUE_RGB[3] = {255, 228, 196};
const byte NAVAJOWHITE_RGB[3] = {255, 222, 173};
const byte WHEAT_RGB[3] = {245, 222, 179};
const byte BURLYWOOD_RGB[3] = {222, 184, 135};
const byte TAN_RGB[3] = {210, 180, 140};
const byte ROSYBROWN_RGB[3] = {188, 143, 143};
const byte SANDYBROWN_RGB[3] = {244, 164, 96};
const byte GOLDENROD_RGB[3] = {218, 165, 32};
const byte DARKGOLDENROD_RGB[3] = {184, 134, 11};
const byte PERU_RGB[3] = {205, 133, 63};
const byte CHOCOLATE_RGB[3] = {210, 105, 30};
const byte SADDLEBROWN_RGB[3] = {139, 69, 19};
const byte SIENNA_RGB[3] = {160, 82, 45};
const byte BROWN_RGB[3] = {165, 42, 42};
const byte MAROON_RGB[3] = {128, 0, 0};
const byte WHITE_RGB[3] = {255, 255, 255};
const byte SNOW_RGB[3] = {255, 250, 250};
const byte HONEYDEW_RGB[3] = {240, 255, 240};
const byte MINTCREAM_RGB[3] = {245, 255, 250};
const byte AZURE_RGB[3] = {240, 255, 255};
const byte ALICEBLUE_RGB[3] = {240, 248, 255};
const byte GHOSTWHITE_RGB[3] = {248, 248, 255};
const byte WHITESMOKE_RGB[3] = {245, 245, 245};
const byte SEASHELL_RGB[3] = {255, 245, 238};
const byte BEIGE_RGB[3] = {245, 245, 220};
const byte OLDLACE_RGB[3] = {253, 245, 230};
const byte FLORALWHITE_RGB[3] = {255, 250, 240};
const byte IVORY_RGB[3] = {255, 255, 240};
const byte ANTIQUEWHITE_RGB[3] = {250, 235, 215};
const byte LINEN_RGB[3] = {250, 240, 230};
const byte LAVENDERBLUSH_RGB[3] = {255, 240, 245};
const byte MISTYROSE_RGB[3] = {255, 228, 225};
const byte GAINSBORO_RGB[3] = {220, 220, 220};
const byte LIGHTGRAY_RGB[3] = {211, 211, 211};
const byte SILVER_RGB[3] = {192, 192, 192};
const byte DARKGRAY_RGB[3] = {169, 169, 169};
const byte GRAY_RGB[3] = {128, 128, 128};
const byte DIMGRAY_RGB[3] = {105, 105, 105};
const byte LIGHTSLATEGRAY_RGB[3] = {119, 136, 153};
const byte SLATEGRAY_RGB[3] = {112, 128, 144};
const byte DARKSLATEGRAY_RGB[3] = {47, 79, 79};
const byte BLACK_RGB[3] = {0, 0, 0};
const byte *HTML_COLORS[] = {
  CYAN_RGB, LIGHTCYAN_RGB, PALETURQUOISE_RGB, AQUAMARINE_RGB, TURQUOISE_RGB, MEDIUMTURQUOISE_RGB, DARKTURQUOISE_RGB,
  CADETBLUE_RGB, STEELBLUE_RGB, LIGHTSTEELBLUE_RGB, POWDERBLUE_RGB, LIGHTBLUE_RGB, SKYBLUE_RGB, LIGHTSKYBLUE_RGB, DEEPSKYBLUE_RGB,
  DODGERBLUE_RGB, CORNFLOWERBLUE_RGB, /*MEDIUMSLATEBLUE_RGB,*/ ROYALBLUE_RGB, BLUE_RGB, MEDIUMBLUE_RGB, DARKBLUE_RGB, NAVY_RGB,
  MIDNIGHTBLUE_RGB,
  CORNSILK_RGB, BLANCHEDALMOND_RGB, BISQUE_RGB, NAVAJOWHITE_RGB, WHEAT_RGB, BURLYWOOD_RGB, TAN_RGB, ROSYBROWN_RGB, SANDYBROWN_RGB,
  GOLDENROD_RGB, DARKGOLDENROD_RGB, PERU_RGB, CHOCOLATE_RGB, SADDLEBROWN_RGB, SIENNA_RGB, BROWN_RGB, MAROON_RGB,
  WHITE_RGB, SNOW_RGB, HONEYDEW_RGB, MINTCREAM_RGB, AZURE_RGB, ALICEBLUE_RGB, GHOSTWHITE_RGB, WHITESMOKE_RGB, SEASHELL_RGB,
  BEIGE_RGB, OLDLACE_RGB, FLORALWHITE_RGB, IVORY_RGB, ANTIQUEWHITE_RGB, LINEN_RGB, LAVENDERBLUSH_RGB, MISTYROSE_RGB,
  GAINSBORO_RGB, LIGHTGRAY_RGB, SILVER_RGB, DARKGRAY_RGB, GRAY_RGB, DIMGRAY_RGB, LIGHTSLATEGRAY_RGB, SLATEGRAY_RGB, DARKSLATEGRAY_RGB,
  BLACK_RGB
};
enum HTML_COLOR_NAMES {
                       CYAN, LIGHTCYAN, PALETURQUOISE, AQUAMARINE, TURQUOISE, MEDIUMTURQUOISE, DARKTURQUOISE,
                       CADETBLUE, STEELBLUE, LIGHTSTEELBLUE,
                       POWDERBLUE, LIGHTBLUE, SKYBLUE, LIGHTSKYBLUE, DEEPSKYBLUE, DODGERBLUE, CORNFLOWERBLUE,
                       /*MEDIUMSLATEBLUE,*/ ROYALBLUE, BLUE, MEDIUMBLUE,
                       DARKBLUE, NAVY, MIDNIGHTBLUE,
                       CORNSILK, BLANCHEDALMOND, BISQUE, NAVAJOWHITE, WHEAT, BURLYWOOD, TAN, ROSYBROWN, SANDYBROWN,
                       GOLDENROD, DARKGOLDENROD, PERU,
                       CHOCOLATE, SADDLEBROWN, SIENNA, BROWN, MAROON,
                       WHITE, SNOW, HONEYDEW, MINTCREAM, AZURE, ALICEBLUE, GHOSTWHITE, WHITESMOKE, SEASHELL, BEIGE,
                       OLDLACE, FLORALWHITE, IVORY,
                       ANTIQUEWHITE, LINEN, LAVENDERBLUSH, MISTYROSE,
                       GAINSBORO, LIGHTGRAY, SILVER, DARKGRAY, GRAY, DIMGRAY, LIGHTSLATEGRAY, SLATEGRAY, DARKSLATEGRAY, BLACK
                      };
void setup() {
  Serial.begin(9600);
  Serial.print(HTML_COLORS[DARKBLUE][0]);
  Serial.print(", ");
  Serial.print(HTML_COLORS[DARKBLUE][1]);
  Serial.print(", ");
  Serial.println(HTML_COLORS[DARKBLUE][2]);
}
void loop() {}

Do the arrays have to be byte arrays or can they be int arrays?

1204NeRd: Do the arrays have to be byte arrays or can they be int arrays?

certainly, but if you are storing values (like RGB PWM) that are 8 bit, why would you want to use 16bit types to store them?

I think I've got it working, but I have one question. How are the enum and pointer array related, since they have different names, and their contents are named differently as well?

1204NeRd:
Do the arrays have to be byte arrays or can they be int arrays?

They can be int arrays and take up twice as much space. Did you need to store values over 255?

1204NeRd:
I have one question. How are the enum and pointer array related, since they have different names, and their contents are named differently as well?

The enum (enumeration) assigns a number to each name. CYAN is 0, LIGHTCYAN is 1, etc. You can use those names to select a particular entry from the table. Or you can use the named arrays directly. HTML_COLORS is roughly equivalent to CYAN_RGB. Usually you will just index into the table in a loop:

for (int color = 0; color < sizeof HTML_COLORS / sizeof HTML_COLORS[0]; color++) {
    Serial.print("Color #");
    Serial.print(color);
    Serial.print(" has RGB ")
    Serial.print(HTML_COLORS[color][0]);
    Serial.print(", ");
    Serial.print(HTML_COLORS[color][1]);
    Serial.print(", ");
    Serial.println(HTML_COLORS[color][2]);
}

I got it to work. Thanks for all the help!