GFX Lib + Text Print - Refresh a Text Line?

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
awardblvr
 
Posts: 19
Joined: Tue Sep 24, 2013 6:53 pm

GFX Lib + Text Print - Refresh a Text Line?

Post by awardblvr »

Using the default font with Adafruit GFX library and ESP32-S2-TFT board, I need to refresh the last line of the display every so often with a new line of text.

I really don't want to disturb or re-write the other parts of the screen.

How can I blank just that bottom text line so I can refresh it with updated text?

I tried

Code: Select all

tft.print("                    ")
,
but of course, all the previous pixels set by previous writes remain asserted.
Any suggestions?

User avatar
atroph
 
Posts: 3
Joined: Mon Nov 07, 2022 11:38 pm

Re: GFX Lib + Text Print - Refresh a Text Line?

Post by atroph »

I registered here for something very similar to this.

I'm using "TFT_eSPI.h" to do a simple clock demo and if I set the font color with:

Code: Select all

tft.setTextColor(TFT_BLUE, TFT_BLACK);
(blue is font, black is background of the font) it writes and updates the TFT ok given that my background is also black.

However if I want to display just the font color without its associated background with

Code: Select all

tft.setTextColor(TFT_BLUE);
every time the hour or minute changes it'll overwrite on top of the previous number and become a jumbled mess.

I'd much rather have the font be background independent and not have to have a matching background canvas of a solid color to rid of the surrounding blocks around the letters and numbers.

Wonder if there is something similar to a horizontal or vertical blank similar to analog TVs that I'm missing?

User avatar
atroph
 
Posts: 3
Joined: Mon Nov 07, 2022 11:38 pm

Re: GFX Lib + Text Print - Refresh a Text Line?

Post by atroph »

Few options I have read that may work.

1. Loop your routine for the area that you want to update twice.

Pseudocode:

Code: Select all

updateTextArea(){
setTextColor(background)
move to x/y position
write old text that may or may not be still stored in left over variables
setTextColor(regularcolor)
load new values in variables
write new text
2. Use both arguments

Code: Select all

tft.setTextColor(TFT_BLUE, TFT_BLACK);
with the given TFT library to set the text color AND the background color of the text.

3. Write full blocks in background color in the area that you want to update, then execute your normal write text routine.

Code: Select all

[b]Encodings[/b]
HTML Entity (decimal)	█
HTML Entity (hex)	█
How to type in Microsoft Windows	Alt +2588 Alt 219
UTF-8 (hex)	0xE2 0x96 0x88 (e29688)
UTF-8 (binary)	11100010:10010110:10001000
UTF-16 (hex)	0x2588 (2588)
UTF-16 (decimal)	9,608
UTF-32 (hex)	0x00002588 (2588)
UTF-32 (decimal)	9,608
C/C++/Java source code	"\u2588"
Python source code	u"\u2588"
For now I'm just going to stick with a static background color and use the two argument set text color function (option 2). It works just fine.

User avatar
atroph
 
Posts: 3
Joined: Mon Nov 07, 2022 11:38 pm

Re: GFX Lib + Text Print - Refresh a Text Line?

Post by atroph »

Here is the code page for a full block. https://www.fileformat.info/info/unicod ... /index.htm

User avatar
awardblvr
 
Posts: 19
Joined: Tue Sep 24, 2013 6:53 pm

Re: GFX Lib + Text Print - Refresh a Text Line?

Post by awardblvr »

Thanks Everyone...

I created a solution for my needs... It assumes:
  • I own the full line,
  • I am only using default font, size 1,2,3
  • Only want colored text on black background.

Code: Select all

void clearSizedTextLine(int8_t fontSize, int8_t pixelLine)
{
    int chars=0;

    switch (fontSize) {
        case 1:
            chars=41;
            break;
        case 2:
            chars=21;
            break;
        case 3:
            chars=14;
            break;
        default:
            return;
    }

    tft.setTextSize(fontSize);
    tft.setCursor(0 /*x*/, pixelLine);
    tft.setTextColor(ST77XX_BLACK);
    while (--chars) {
        tft.print(char(0xDA)); // 0xDA is the CP437(false) square block
    }
    tft.setCursor(0 /*x*/, pixelLine);
}
... which I call with something like:

Code: Select all

#define DISP_BOTTOM_WARN_PIXEL 114
#define DISP_BOTTOM_WARN_SIZE 3

clearSizedTextLine(DISP_BOTTOM_WARN_SIZE, DISP_BOTTOM_WARN_PIXEL);
tft.setTextColor(ST77XX_RED);
tft.print("REBOOT in 4");
delay(4000);
ESP.restart();

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

Return to “Arduino”