Call function with * bitmap parameter

Heyho,

I have a beginner question and struggle to find a proper solution.

const unsigned char logo[] PROGMEM = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }

  u8g2.drawXBM(0, 5, 50, 50, logo);

This works for me - but it`s not really flexible and handy.

I thought something like this: The array has all the bitmap names in it. I want to iterate the array and call the draw function.

 String myarray[] = {
   "logo1",
   "logo2",
   "logo3",
   "logo4"
 };

  u8g2.drawXBM(0, 5, 50, 50, myarray[3]);

Bute nope - that doesn't work.
How can I call the function with the array values?

Thanks for your help
Greetings

If one was to look t the documentation for the u8g2 library one may find

void u8g2_DrawXBM(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, const uint8_t *bitmap

Which explains why String is not working.

u8g2reference · olikraus/u8g2 Wiki (github.com)

The String class ought to be banned, really. About one half of all the problems we see in this forum are String-related one way or the other. The other half is everything else.

But the array names don't exist after compilation.

My question is:
How can I call the function with the array values or can call it in an other way than writing in the bitmap name?

I use the String class. It does not cause issues with proper use.

Hello

See the example "array of strings" on this page

It shows how to make an array of pointers (to strings, but can be anything else) and how to retrieve the data from this pointer.

...and therein lies the problem.

I think it depends on the platform too.

1 Like
const unsigned char * myarray[] = {
   logo1,
   logo2,
   logo3,
   logo4
 };
1 Like

@johnwasser , thank you very much for your answer! That`s what i searched for
greetings from austria