Array of arrays?

Hi guys, just wondering if its possible to make an array of multiple arrays.

Some background on the project: I have an AMG8833 and I have built multiple arrays of color pallets for it. The color pallets can be changed during runtime. I also use the color pallets for other things during runtime.

I would like to somehow make an array of arrays, to make it easier to pull from the arrays.

something like:

  uint32_t IRONBOW [] {
  some HEX numbers
  uint32_t RAINBOW [] {
 some more HEX numbers

at the moment I have it set up like this:

 uint32_t     nCamColor_HEX;
      if (thermalCol == 0) {
        nCamColor_HEX = IRONBOW [colorIndex];
      else if (thermalCol == 1) {
        nCamColor_HEX = RAINBOW [colorIndex];
      else if (thermalCol == 3) {
        nCamColor_HEX = BLACK_HOT [colorIndex];
      else if (thermalCol == 4) {
        nCamColor_HEX = WHITE_HOT [colorIndex];
      else if (thermalCol == 2) {
        nCamColor_HEX = ARCTIC [colorIndex];
      else if (thermalCol == 6) {
        nCamColor_HEX = OUTDOOR_ALERT [colorIndex];

I would much rather do away with the if/else chain and have it set up like this:

uint32_t nCamColor_HEX = colorPalletesArray[thermalCol] [colorIndex];

Could someone give me some pointers on how to do it?
Thanks :slight_smile:


Where xx is the number of two dimensional array

You can use 2 dimensional arrays as long as the sub arrays are all of the same type and have the same number of elements

byte twoDimArray[][3] =
  {1, 2, 3},
  {4, 5, 6},
  {7, 8, 9}

void setup()
  while (!Serial);
  Serial.println(twoDimArray[2][2]);  //just to prove it works

void loop()

So if i have 6 arrays, each with 433 elements, then I would write it like this?

uint32_t colorPallet[][433] = {
  {433 HEX numbers}
  {another 433 HEX numbers}
  {the 6th group of 433 HEX numbers}


//thermalCol is which array, and colorIndex is which element in the array
uint32_t nCamColor_HEX = colorPallete[thermalCol] [colorIndex];

if i have 6 arrays, each with 433 elements, then I would write it like this?

Yes, but don't forget the commas at the end of the lines and make sure that the principle works in your situation before putting too many entries in the array

Which Arduino board are you using ?
6 * 433 * 4 bytes is a lot of memory

Is there any logic or pattern to the values in the arrays that could be used to avoid the need for the arrays ?

I am using an ESP32. I still have alot of memory left over.
I was using some math to generate RGB values during runtime, but i found arrays to be much faster, so I made a sketch to produce some arrays from the RGB math, and now use them instead.

I am using an ESP32.

That's a relief

It is no surprise that using arrays is faster but maybe your calculation code could be optimised. Does it use floats, for instance ?

Here is an example for the IRONBOW pallete:

#define MINTEMP 21
#define MAXTEMP 29
Adafruit_AMG88xx amg;
#define AMG_COLS 8
#define AMG_ROWS 8
float pixels[AMG_COLS * AMG_ROWS];
#define INTERPOLATED_COLS 36      
int boxWidth = 7;
int boxHeight = 5;
byte red, green, blue;
float a,b,c,d;
float get_point(float *p, uint8_t rows, uint8_t cols, int8_t x, int8_t y);
void set_point(float *p, uint8_t rows, uint8_t cols, int8_t x, int8_t y, float f);
void get_adjacents_1d(float *src, float *dest, uint8_t rows, uint8_t cols, int8_t x, int8_t y);
void get_adjacents_2d(float *src, float *dest, uint8_t rows, uint8_t cols, int8_t x, int8_t y);
float cubicInterpolate(float p[], float x);
float bicubicInterpolate(float p[], float x, float y);
void interpolate_image(float *src, uint8_t src_rows, uint8_t src_cols,
                       float *dest, uint8_t dest_rows, uint8_t dest_cols);

void setup()

void loop()
  interpolate_image(pixels, AMG_ROWS, AMG_COLS, dest_2d, INTERPOLATED_ROWS, INTERPOLATED_COLS);
  drawpixels(dest_2d, INTERPOLATED_ROWS, INTERPOLATED_COLS, boxWidth, boxHeight, false);

void drawpixels(float *p, uint8_t rows, uint8_t cols, uint8_t boxWidth, uint8_t boxHeight, boolean showVal) { //From Adafruit example
  int colorTemp;
  for (int y = 0; y < rows; y++) {
    for (int x = 0; x < cols; x++) {
      float val = get_point(p, rows, cols, x, y);

//Begin RGB math

      red = constrain(255.0 / (c - MINTEMP) * val - ((MINTEMP * 255.0) / (c - MINTEMP)), 0, 255);
      green = constrain(255.0 / (MAXTEMP - b) * val - ((b * 255.0) / (MAXTEMP - b)), 0, 255);
      if ( val <= a) { //finished
        blue = constrain(160.0 / (a - MINTEMP) * val - (160.0 * MINTEMP) / (a - MINTEMP), 20, 160);
      if ((val >= a) & (val <= b)) {
        blue = 160;
      else if ((val >= b) & (val <= c)) { //finished
        blue = constrain(160.0 / (b - c) * val - (c * 160.0) / (b - c), 0, 160);
      else if ((val >= c) & (val <= d)) { //finished
        blue = 0;
      else if (val >= d) { //finished
        blue = constrain(225.0 / (MAXTEMP - d) * val - (d * 225.0) / (MAXTEMP - d), 0, 225);
//End RGB math

      gslc_tsRect rCamRect = {
        boxWidth * x,
        boxHeight * y,
      gslc_tsColor nCamCol_rgb = { red, green, blue};
      gslc_DrvDrawFillRect(&m_gui, rCamRect, nCamCol_rgb);



void Getabcd() {
  a = MINTEMP + (MAXTEMP - MINTEMP) * 0.2;
  b = MINTEMP + (MAXTEMP - MINTEMP) * 0.4;
  c = MINTEMP + (MAXTEMP - MINTEMP) * 0.6;
  d = MINTEMP + (MAXTEMP - MINTEMP) * 0.8;

I kinda hacked it together. Its a kind of twisted lovechild from Kris Kasprzak’s and Adafruits AMG8833 interpolation examples.

With all those floats I am not surprised that using arrays speeded things up

Do they have to be floats or could the calculations be done with integers, which would be much faster, and converted to a float if necessary before using the value ? How many decimal places do the floats have to be ?

I havent had a proper look into is, but i can say without looking that definitely some of them are neccessary as the colors are to be mapped to floats. I have had problems with ints as generally speaking the temperature difference in the picture is around 10 degrees C, but I want more than 10 colors at any one time.

Its definitely something that requires further investigation and testing. I really need to spend decent couple of hours playing around with it to see if its possible, but storage isnt a problem at the moment, an I dont think it would be any faster than an array anyway.

I really do appreciate the help, and if I make any progress regarding your suggestions I will be sure to let you know.

If your feeling creative and want to take a look at it, here is the original code:

Here is a video about the project from the author:

and here are some snippets of my modified RGB math:

And here are linearised versions of the color pallets:!Au33JFgjzjs9ggtZSl-KnVF3JJmU?e=406A7q

I do not expect any help with this, I only post it for your curiosity. I am more than happy with using arrays.
However, if you do help, I wont complain, and it may help others in the future.

hey just want to say for next time say or and not 'of' :confused:

If you actually paid attention to what is going on here you would see i was asking about building an array that contains multiple arrays. An "array of arrays" if you will.

Please do not post things that are not helpful

You can create 2D array ,basically it is jagged array which has sub arrays with different size

You can create 2D array ,basically it is jagged array which has sub arrays with different size

I can't quite visualise what you mean. Can you please provide an example declaration and use of such an array