Using "canvas" on the Adafruit GFX Library

Hi guys, I am a beginner, so please be gentle.
I am playing with a TFT display connected to an STM32F103RET6 board.
All fine until I try to increase/decrease numbers using custom fonts. It looks like the library does not accept background color on the custom fonts, only on default fonts. Like this, the previous text will not be cleared.
there are a couple solutions:
Draw a rectangle filled with the background color before writing the next text.
This works, but the text flickrers.

The other solution is to use canvas and draw it as a bitmap. the problem I am having is that it still does not clear the text underneath. I am sure I am doing something wrong, but I cannot find any more information apart from the one on the adafruit tutorial. Here is the relevant code:

GFXcanvas1 canvas(152, 78); // Create canvas object

canvas.setFont(&FreeSans24pt7b);
canvas.setTextSize(2);

for (int i = 0; i < 200; i++) {
sprintf (buffer, "%03d", i);
canvas.setCursor(0, 74);
canvas.print(buffer);
tft.drawBitmap(160, 74, canvas.getBuffer(), 152, 78, ILI9341_WHITE, ILI9341_BLACK); // Copy to screen

delay(200);

}

Thank you so much for your help. By the way, I cannot see any "code" button above.

The 'text' is flickering because it keeps getting wiped and rewritten in the loop. Try to only write it once, and only if if it has changed...

is the txt limited to only a few characters or words? you could try a text array something like these snippets...

void setup() {

char* MenuLine[] = {"LASER GUN", "PLASMA GUN", "PHOTON GUN", "DISINTEGRATOR", "DISRUPTOR", "PLASMA CANNON", "GRENADE"};

 
void loop ()//call the  menu only as needed
 print_menu();
}

//ORDNANCE MENU
void print_menu() {
  tft.setTextSize(2);
  tft.setCursor(115, 20);
  tft.setTextColor(0x0000);
  tft.print([MenuLine] ); //0,1,2,3,4..etc
 }

Hi thanks for your reply.
this text will be preset numbers from 000 to 199.
I can make it work with display flicker. My problem is that the Bitmap solution is not working as they say. it doesn't clear the previous text. And this is what I would like to fix. as I said, I am sure I am making some stupid mistake

For the ones with similar problem.. Found this.. It seems to work well

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.