How to avoid text flicker ?
-
I am writing text to the same location with updated values. I get the text superimposed on the old text. i use a space, the reset the setCursor, then write the new text. But I get flicker - How to avoid this ? Also if you make a filled rectangle and then write text on it - the whole thing flickers like mad.
-
Just save previous displayed value in global variable, before display compare with saved, and display only if they differs.
-
this is a good option as @Sergey_Urusov wrote,
instead rectangle you can also overwrite old value with inverted color
something like this:#include <M5Stack.h> void setup() { M5.begin(); M5.Lcd.fillScreen(BLACK); M5.Lcd.setTextSize(7); } void loop(){ static int rndold = -1; int rnd = random(0, 100); if (rnd != rndold) { //overwrite old value with inverted color M5.Lcd.setCursor(40, 40); M5.Lcd.setTextColor(BLACK); M5.Lcd.printf("%02d", rndold); //write new value M5.Lcd.setCursor(40, 40); M5.Lcd.setTextColor(WHITE); M5.Lcd.printf("%02d", rnd); rndold = rnd; delay(250); } }
-
You can try PrintToSprite in the TFT_eSPI library. https://github.com/Bodmer/TFT_eSPI/issues/116
-
Here is the solution. https://github.com/Bodmer/TFT_eSPI/tree/master/examples/Sprite/Sprite_scroll
Thanks to @Calin