How to display picture base on an int input?

Hello! I am struggling on something that seem simple but I have failed to do. I think I might have missed something fundamental? I tried searching on google, but no luck, might be using wrong keywords? Any help would be greatly appreciated!

Anyway, question is:

I have the a list of bitmaps converted using image2LCD as follows:

const unsigned char icon_1[288]
const unsigned char icon_2[288]
.
.
.
const unsigned char icon_30[288]

int n = 1;

I have inputs that are int n which is 1 -30, how do I display icon(n) when I have int n?

i.e. If I have int n, the display would draw:
display.drawBitmap(x pos, y pos , icon_n ,width, height, color);

display.drawBitmap (x pos, y pos , "icon_" + n ,width, height, color);

-> error: invalid operands of types 'const char*' and 'const char [2]' to binary 'operator+'

String str_n = String(n);
display.drawBitmap (x pos, y pos , "icon_" + n ,width, height, color);

-> Gives a bunch of error starting with
error: no matching function for call to 'drawBitmap(int, int, const char*, int, int, uint16_t&)'

char iconname[12];
sprintf (iconname, "icon_%d", n);

-> Gives a bunch of error starting with
error: no matching function for call to 'drawBitmap(int, int, char [12], int, int, uint16_t&)'

... also tried other things I can think of without success.

I am using ADAFRUIT_GFX with GxEPD2. By looking at the errors I think it needs a const uint8_t* as the 3rd argument, how do I do that? What am I missing that I should read more on?

Thank you!

Put them in an array and just call that index in the array. Btw arrays are zero indexed so the first image will be 0 not 1, unless you put an empty block of data at index 0

Look at the examples in the relevant library.

How do I do that? Each icon_n are already arrays themselves.

Thanks for being not helpful. I have already tried for days before asking.

A two dimensional array. An array of arrays.

1 Like

My apologies, normally the examples are a good teaching tool, certainly better than YT, but I just spent a few minutes trying some of your libraries and I still can't find a good example. I think however you have been given the answer by some others.

Okay, so I tried putting the icons in an array of array, the code complies, but it won't display any image: There are 30 arrays each with length of 288.

const unsigned char Myarray [30][288] =
{ (icon_1 array), (icon_2 array),.... (icon_30 array)};

display.drawBitmap (xpos, ypos, Myarray[n-1], width, height, color);

Google result have suggested using a pointer

const unsigned char* pointer = Myarray[n-1];

Still no image.

I can confirm the images are okay because they print successfully when I have them each as they own arrays, now I have no idea what's wrong.

This is not correct syntax.

The initialization should look like this

const unsigned char Myarray [30][288] =
{ 
 {288 values of icon_1 array},
 {288 values of icon_2 array},
 .
 .
 {288 values of icon_30 array}
};
3 Likes

Oh, sorry for the silly mistake. That works now and I have learnt something new! Thank you so much for everyone's help.