Make keywords variable

Hi!

I wrote a very long piece of code to control 10 different tft displays, making use of the "select/case" method.
However, it would be much easier if I can use a single function, with an extra argument, to change the screen it displays on dynamically.

That means, I now have ten times this:

Void drawSomething1 (bmp);

tft1.startWrite();
tft1.setAddrWindow();
tft1.endWrite();

Void drawSomething2 (bmp);

tft2.startWrite();
tft2.setAddrWindow();
tft2.endWrite();

etc.

i would need something like this

Void drawSomething (bmp, selectedscreen);

selectedscreen.startWrite();
selectedscreen.setAddrWindow();
selectedscreen.endWrite();

In this way one function would take care of everything.

But: When I try to use a variable instead of tft1, tft2, etc, the library doesn't recognize the command anymore.

Can anybody point me in the right direction for solving this?

Thanks in advance!

Best regards
Bart

It would be much easier to help if you included your full code so we could see how things are defined.

Lacking that, I can only give a general answer: pass a pointer to the tft object that you want to use.

Pointers!

Something similar to:

void drawSomething (uint8_t *inbmp, TFTscreen *selectedscreen) {
  selectedscreen->startWrite();
    :
}
   :

   drawSomething(bmp, &tft1);

Or arrays!

screenType tft[10];

void drawSomething(Something a, byte index)
{
  tft[index].startWrite();
  tft[index].setAddrWindow();
  tft[index].endWrite();
}

Or arrays of pointers!

screenType *tft[10] = {tft1, tft2, tft3, ...};

void drawSomething(Something a, byte index)
{
  tft[index]->startWrite();
  tft[index]->setAddrWindow();
  tft[index]->endWrite();
}