Hello, I am not sure if I should have posted this in the programming forum or the LCD display forum. Please move this thread if this should have been elsewhere.
I have an ILI9341 display with 320*240 resolution that I am using with an esp8266 nodemcu board.
I am using the tft_eSPI library. I am trying to update the value of a variable on the screen without updating the entire screen, as doing the latter causes flicker.
After doing some reading I got to know that I need to clear the area of the screen first and then rewrite the new value. After a lot of trial and error I realized that writing an empty string in this library does not clear that portion of the screen. What I did instead was that I printed a rectangle with a color - that effectively clears that area of the screen and then I write the new value.
So this works -
static int i = 0;
char buffer[20] = "";
void loop() {
tft.drawString("Hello world", my_x_pos + 100, my_y_pos + 100,2);
if(i>20)
{
i=0;
}
sprintf(buffer,"%d",i);
Serial.println(buffer);
i++;
tft.fillRect(my_x_pos,my_y_pos,16,16,TFT_BLACK); //height and width of rectangle in pixels
tft.drawString(buffer,my_x_pos,my_y_pos,2);
delay(200);
}
but this doesn't -
static int i = 0;
char buffer[20] = "";
void loop() {
tft.drawString("Hello world", my_x_pos + 100, my_y_pos + 100,2);
if(i>20)
{
i=0;
}
sprintf(buffer,"%d",i);
Serial.println(buffer);
i++;
tft.drawString(" ",my_x_pos,my_y_pos,2);
tft.drawString(buffer,my_x_pos,my_y_pos,2);
delay(200);
}
Am I doing this right? If I am, is there a better way of doing this? By doing it this way I need to know the pixel values of the height and width of each text size. I got the current values using trial and error.
I looked at the example programs in the library repo, and I don't see this method being used there.