[/code]
Like this it displays i++ numbers correctly but they are blinking since after every loop cycle there is tft.fillScreen(ILI9341_WHITE);
Now if i remove tft.fillScreen(ILI9341_WHITE); then numbers start to overwrite themselves and i end up with black squares (previous numbers are not ‘deleted’ and new ones are printed on top).
What am i doing wrong? Or is there some problem with this library?
The problem here is that only the characters are drawn and not their background color.
So you do need the tft.fillScreen(ILI9341_WHITE); line, but I would put it directly before the tft.print(i); line to reduce the time between “clearing” the screen and reprinting and hence reduce flicker.
Some possible other solutions would be to set the text backcolor or to use double buffering - but I’m not sure if this is available in this display lib.
I think @ScruffR is right here–the display is doing what you told it to do, just not what you want. His solution is a good idea but I have two other points:
You don’t have to fill the entire screen with white, you can just draw a white rectangle that covers the text area before writing a new number
You can also draw the old value in white to erase it back to background and then draw the new value in black. This simulates an XOR drawing mode which this display does not seem to have.
tft.setTextColor(ILI9341_WHITE);
tft.setCursor(50,50);
tft.print(i); //erase old
i++;
tft.setTextColor(ILI9341_BLACK);
tft.setCursor(50,50);
tft.print(i); //print new
The rectangle method may be faster since you don’t have to render fonts–it depends on the controller that is being used.
That’s right, I totaly ignored the rect-route since when I had a similar problem with my RGB-LED matrix that also uses Adafruit_mfGFX lib I found that filling the entire screen white or black (or some other special colors) via memcpy it was way faster than rect, but this was only due to some peculiarities of that display, which don’t play any role for your display
After trying all the options is stumbled across this while googling:
[quote]Folks,
Y’all making same mistake (for what you are trying to do) - providing single color argument.
If
you carefully read API notes you will notice that tft.setTextColor can
take either one or two arguments. If single argument provided - it will
print text color with clear background (junk pixels will accumulate). If
two arguments provided - it will fill background of each character with
color of second argument.
Nice and simple. No need for any blank space overwrite before new print.[/quote]
This option works best for me: tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);