I am trying to display successive numbers on an Adafruit TFT touchscreen display. As I increment the number it overwrites itself on the screen, eventually obscuring the entire number.
Is there a way to clear the text before I write another number? I am using the ILI9341 library.
The application is a touch screen tuner for a programmable oscillator. Touch sceen instead of a rotary encoder.
Use tft.setTextColor(WHITE, BLACK) to set the background colour. If you use the setTextColor(WHITE) method, the foreground is WHITE but it does not draw the background colour.
Obviously 65536 different colours are available. Common colours might have a #define e.g. YELLOW, BLUE, ....
david_prentice:
Use tft.setTextColor(WHITE, BLACK) to set the background colour. If you use the setTextColor(WHITE) method, the foreground is WHITE but it does not draw the background colour.
@david_prentice: I'm not the original poster, but I just wanted to say thanks for this. I've been writing my text/values in white, then drawing a black rectangle over the white text, then rewriting the updated text/values in white again. It works, but clearly the method you mentioned is better and more efficient. It's still early in the morning, but I guarantee this will be the best thing that I learn today.
would let you specify different numbers of decimals.
after all, you normally just say print(floatvalue) without specifying the second argument i.e. decimals.
If you look in the "Adafruit_GFX.cpp" you will see the following.
void Adafruit_GFX::setTextColor(uint16_t c) {
// For 'transparent' background, we'll set the bg
// to the same as fg instead of using a flag
textcolor = textbgcolor = c;
}
void Adafruit_GFX::setTextColor(uint16_t c, uint16_t b) {
textcolor = c;
textbgcolor = b;
}
If you only want to Draw the Character with a transparent background meaning you only write the character
setTextColor in the prescribed pixels changing none of the surrounding pixels in the character block defined by x, y, setTextSize.
TFT.setTextColor(GREEN); //With Transparent Text Background not updating surrounding pixels.
If you want to Draw the Character with your background color, replace app pixels in the character block defined by x, y, setTextSize with your chosen text color and your background to be the same as your chosen background. This will overwrite all pixels with old character that are no longer used with the background color all at the same time preventing mess of pixels, and character flashing.
<code]
TFT.setTextColor.setTextColor(GREEN, BLACK); //With Text Background Color updating surrounding pixels.
[/code]