Clearing characters in TFT or Oled Displays

Hey Guys!
Im started to display characters on a !graphical! display (its a M5StickC with esp32 and TFT color display).

It is important that we not talk about lcd like, character/digit numbers based display!

The problem is classical. If my variable = 10. It is displayed correctly. But when the value decrease to 9, the display shows: 90 ... of course, of course... "the characters remains unchanged until it is overwritten".

So far i did not see real working solution. That is how i tried:

  1. i wrote an if statment: if variable less than 10 >> put the cursor to the second character. So it will be not 90 it will be 09 or 9... right? ... Of course not... it will be 19

  2. Fill the screen or fill some rectangle. >> not good >> the screen will flicker.

2.2 Fill the screen or fill some characters rectangle WITH TIMER... (in every 500millisec fill/draw etc.) >> kinda works... but it gives you good result only slowly.... if you increase the update time, the slower it dislpay the correct value. And you still get some flicker on every update. If you update/draw faster... yes you get mooorrreee flicker.

  1. You combine everythig above. You write an if statment, about the number of characters and combine it with some conditional fill.rectangle. You gone be spot on!

BUT... It is freakin ~20 lines of code to display a 2digit character correctly!?!? And that is just one variable.

So any ideas anybody? Is there any solution i miss? So wierd in 2022 to deal this kind of silly. Any ideas are welcome!
Ben

It usually takes only 1 or 2 extra lines of code to solve that problem. Post your code, using code tags.

So wierd in 2022 to deal this kind of silly

Not at all. Writing graphic display code has always been and always will be a pain in the butt, because everyone has different requirements.

4th option:
Save the previous value of the number.
Set text color to match background.
Print previous value to screen at appropriate cursor position.
Set text color to your normal text color.
Print new value to screen at appropriate cursor position.

Generally any flicker is unnoticeable, because you only print when the value changes .

1 Like

Here are some code example

Start value:
int i = 2147483630;

Display code:
M5.Lcd.setCursor(20,20);
M5.Lcd.print(i);

So i see this:
2147483630

Purpose >> if i=9; >> let see this:
9 or this:
"........9" (please ignore the dots, it is a representation of space) or this:
0000000009

For informed help, and suggestions on effectively posting, please read and follow the instructions in the "How to get the best out of this forum" post.

1 Like

thanks! I will try this one.

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