0

Modifying a certain line from the LCD screen without refresh
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Modifying a certain line from the LCD screen without refresh

by dkanday on Wed Sep 15, 2021 3:10 pm

Hi,

I am trying to display the temperature of the environment using the 1.33" display and whenever the temperature changes I am refreshing the whole screen which kinda visible. Is there a way I can just refresh the temperature value part and not the whole screen. Below is my code snippet:
Code: Select all | TOGGLE FULL SIZE
    tft.fillScreen(ST77XX_BLACK);
    tft.setTextColor(ST77XX_WHITE);
    tft.setCursor(0, 0);
    tft.setTextSize(5);
    tft.println("Temp");
    tft.setTextSize(2);
    tft.println(" ");
    tft.setTextSize(6);
    tft.println(tempvalue);
    tft.setTextSize(1);
    tft.println(" ");
    tft.setTextSize(4);
    tft.println("F");

dkanday
 
Posts: 60
Joined: Mon Jun 07, 2021 4:49 pm

Re: Modifying a certain line from the LCD screen without ref

by adafruit_support_bill on Wed Sep 15, 2021 3:22 pm

Determine the coordinates of a rectangle that covers the area behind the temperature. Use fillRect() to draw that in solid black - instead of using fillScreen() to blank the whole screen. Then print the temperature text on top of it.

adafruit_support_bill
 
Posts: 82172
Joined: Sat Feb 07, 2009 10:11 am

Re: Modifying a certain line from the LCD screen without ref

by dkanday on Wed Sep 15, 2021 4:13 pm

It makes sense. Is there an easy way to determine the coordinates?

dkanday
 
Posts: 60
Joined: Mon Jun 07, 2021 4:49 pm

Re: Modifying a certain line from the LCD screen without ref

by adafruit_support_bill on Wed Sep 15, 2021 4:27 pm

The basic character size is 5x8 pixels. The setPixelSize function is a multiplier for that.
See this part of the guide for details: https://learn.adafruit.com/adafruit-gfx ... 2002798-24
Code: Select all | TOGGLE FULL SIZE
    tft.setCursor(0, 0);
    tft.setTextSize(5);
    tft.println("Temp");

So after this code, your cursor will be at 0,40.
Code: Select all | TOGGLE FULL SIZE
    tft.setTextSize(2);
    tft.println(" ");

Those lines should put you at 0,56. So that would be the upper left corner of your rectangle.
Code: Select all | TOGGLE FULL SIZE
    tft.setTextSize(6);
    tft.println(tempvalue);

For a text size of 6, your rectangle would need to be 8x6 = 48 pixels high. And you would need to make it at least wide enough for the number of digits you want to display.

adafruit_support_bill
 
Posts: 82172
Joined: Sat Feb 07, 2009 10:11 am

Re: Modifying a certain line from the LCD screen without ref

by dkanday on Wed Sep 15, 2021 5:05 pm

Thanks a ton Bill!

dkanday
 
Posts: 60
Joined: Mon Jun 07, 2021 4:49 pm

Re: Modifying a certain line from the LCD screen without ref

by dkanday on Wed Sep 22, 2021 3:03 pm

Hi Bill,

can you please let me know how do I draw a rectangle for my case. i am not sure about the coding part.

dkanday
 
Posts: 60
Joined: Mon Jun 07, 2021 4:49 pm

Re: Modifying a certain line from the LCD screen without ref

by adafruit_support_bill on Wed Sep 22, 2021 3:25 pm

Use the "fillRect" function described here: https://learn.adafruit.com/adafruit-gfx ... 2002784-10

adafruit_support_bill
 
Posts: 82172
Joined: Sat Feb 07, 2009 10:11 am

Re: Modifying a certain line from the LCD screen without ref

by dkanday on Fri Sep 24, 2021 11:05 am

When I am using the fillrect() instead of the fillscreen(). When I rewrite the code I am still having an issue where it refreshes the whole screen(instead of the temp value section).
Here is the piece of code. Since the Arduino runs code line by line it seems to be that refreshing the whole display is the only way I can make the changes visible on the screen.
Is there something that I am missing?
Code: Select all | TOGGLE FULL SIZE
tft.fillScreen(ST77XX_BLACK);
    tft.setTextColor(ST77XX_WHITE);
    tft.setCursor(0, 0);
    tft.setTextSize(5);
    tft.println("Temp");
    tft.setTextSize(2);
    tft.println(" ");
    tft.setTextSize(6);
    tft.fillRoundRect(0, 56, 400, 48, 1, ST77XX_BLACK);
    tft.println(Tempvalue);
    tft.setTextSize(1);
    tft.println(" ");
    tft.setTextSize(4);
    tft.println("F");
    tft.setCursor(0, 0);
    tft.setTextSize(5);
    tft.println("Temp");
    tft.setTextSize(2);
    tft.println(" ");
    tft.setTextSize(6);
    tft.fillRoundRect(0, 56, 400, 48, 1, ST77XX_BLACK);
    tft.println(Tempvalue);
    tft.setTextSize(1);
    tft.println(" ");
    tft.setTextSize(4);
    tft.println("F");

dkanday
 
Posts: 60
Joined: Mon Jun 07, 2021 4:49 pm

Re: Modifying a certain line from the LCD screen without ref

by adafruit_support_bill on Fri Sep 24, 2021 11:54 am

The only time you need to call fillscreen is in your setup. You can draw all of the static parts of the screen at that time. The only code you need to have in your loop is code that updates the variable parts.

adafruit_support_bill
 
Posts: 82172
Joined: Sat Feb 07, 2009 10:11 am

Re: Modifying a certain line from the LCD screen without ref

by dkanday on Fri Sep 24, 2021 12:05 pm

The reason why I have this code here, is in my setup I have the intrenet connection messages which are being printed on the display and in the loop i have a case where it checks if the sensor has been turned on or off. if off, it will display Sensor is off, please turn it on. if on, it will display, the temp value.

dkanday
 
Posts: 60
Joined: Mon Jun 07, 2021 4:49 pm

Re: Modifying a certain line from the LCD screen without ref

by adafruit_support_bill on Fri Sep 24, 2021 12:21 pm

So do that sensor check in a 'while' loop at the end of your setup. Once it is turned on, you can exit that 'while' loop so setup completes. Then it will start to run your main loop() function.

adafruit_support_bill
 
Posts: 82172
Joined: Sat Feb 07, 2009 10:11 am

Re: Modifying a certain line from the LCD screen without ref

by dkanday on Fri Sep 24, 2021 3:32 pm

the issue is that the user would be able to turn on and off the sensor at anytime. That is why I am checking the on and off status in the loop()

dkanday
 
Posts: 60
Joined: Mon Jun 07, 2021 4:49 pm

Re: Modifying a certain line from the LCD screen without ref

by adafruit_support_bill on Fri Sep 24, 2021 6:44 pm

So if it is off, there is no reason to update it - or any of the rest of the screen.

adafruit_support_bill
 
Posts: 82172
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.