Modifying a certain line from the LCD screen without refresh

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
dkanday
 
Posts: 60
Joined: Mon Jun 07, 2021 4:49 pm

Modifying a certain line from the LCD screen without refresh

Post by dkanday »

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

    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");

User avatar
adafruit_support_bill
 
Posts: 88040
Joined: Sat Feb 07, 2009 10:11 am

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

Post by adafruit_support_bill »

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.

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

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

Post by dkanday »

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

User avatar
adafruit_support_bill
 
Posts: 88040
Joined: Sat Feb 07, 2009 10:11 am

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

Post by adafruit_support_bill »

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

    tft.setCursor(0, 0);
    tft.setTextSize(5);
    tft.println("Temp");
So after this code, your cursor will be at 0,40.

Code: Select all

    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

    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.

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

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

Post by dkanday »

Thanks a ton Bill!

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

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

Post by dkanday »

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.

User avatar
adafruit_support_bill
 
Posts: 88040
Joined: Sat Feb 07, 2009 10:11 am

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

Post by adafruit_support_bill »

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

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

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

Post by dkanday »

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

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");

User avatar
adafruit_support_bill
 
Posts: 88040
Joined: Sat Feb 07, 2009 10:11 am

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

Post by adafruit_support_bill »

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.

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

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

Post by dkanday »

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.

User avatar
adafruit_support_bill
 
Posts: 88040
Joined: Sat Feb 07, 2009 10:11 am

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

Post by adafruit_support_bill »

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.

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

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

Post by dkanday »

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()

User avatar
adafruit_support_bill
 
Posts: 88040
Joined: Sat Feb 07, 2009 10:11 am

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

Post by adafruit_support_bill »

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

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”