Hi all.
I am using Arduino IDE, ESP32 and TFT display ILI9341
I need help with the code below.
The function below is called when 'vFloat' changes value.
But the text is being displayed on top of itself, without deleting the previous one.
I though that by, first, displaying a zero value and same background as the text, it would work.
Thank you.
Regards
void display_Vset()
{
tft.setFreeFont(FSS18);
tft.setTextColor(TFT_GREENYELLOW, TFT_GREENYELLOW);
tft.setCursor(100, 85);
tft.printf("%06.3f", 0);
tft.setCursor(100, 85);
tft.setTextColor(TFT_RED, TFT_GREENYELLOW);
tft.printf("%06.3f", vFloat);
}
A popular approach to erasing a specific item of text is to draw a background-filled rectangle over the area. Then write the new value over that.
Another approach is to rewrite the old value in background color, then the new value in foreground color. Drawing speed will be different.
Hi. Thank you for the reply.
I found that neither option works.
I think is because I am using 'TFT_eSPI tft = TFT_eSPI()' custom library.
Your suggestion requires to use '<Arduino_GFX_Library.h>'
correct me if I am incorrect.
Regards
I us e the TFT_eSPI library too and use this code to show the time
time_t nu = DateTime.now();
String tijd = dateTimeToDateString(oldDate, true, false);
ofr.setFontColor(backColor);
ofr.setCursor(120, 35);
ofr.cprintf(" %s ", tijd); // draw the old time in backcolor
tijd = dateTimeToDateString(nu, true, false);
ofr.setFontColor(textColor);
ofr.setCursor(120, 35);
ofr.cprintf(" %s ", tijd);
oldDate = nu;
The same method is usable for other things. I do the same with bitmaps. Rectangle in backcolor and new bitmap after that.
Hi , thank you for the reply.
would you know how to draw a filled rectangle using TFT_eSPI library, please?
I cannot find any reference online.
Regards
b707
August 30, 2023, 7:23pm
6
How did you write that none of the recipes worked if you didn't even try?
See this method
fillRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color);
You did something wrong. Post the code, using code tags, and explain what it did.
Yes you are correct I did something wrong
The code below works fine.
You give me the correct direction.
I believe I did not prefix the command with 'tft. ' earlier.
Thank you very much.
Regards
void display_Vset()
{
tft.fillRect(95,60,120,35,TFT_GREENYELLOW);
tft.setFreeFont(FSS18);
tft.setCursor(100, 90);
tft.setTextColor(TFT_RED, TFT_GREENYELLOW);
tft.printf("%06.3f", vFloat);
}