2.8 TFT rewriting characters "flashes"?

Basically running a small temperature and humidity controller. everything is up and running and working well except that when I change the values they appear to "flash".

I have tried a few things so far, currently I write over the existing number in white (white back screen) then write the new number in black. I have also tried drawing a white rectangle where the number was then rewriting a new one in black but this has the same effect.

Am I missing something?

void currentValues(){
    tft.println(" ");
    tft.println(" ");
    tft.println(" ");
    tft.println(" ");
    tft.println(" ");
    tft.println(" ");
    tft.println(" ");
    tft.setTextSize(2);
    tft.setTextColor(ILI9341_BLACK);
    tft.println("    Current Case");
    tft.print(" Temperature:  ");
    tft.println("C");
    tft.print(" Re/Humidity:  ");
    tft.println("%");
}

void checkInput(){
    TSPoint p = ts.getPoint();
    
     //FOR TEST PURPOSES ONLY
     if (p.z > ts.pressureThreshhold) {
     Serial.print("X = "); Serial.print(p.x);
     Serial.print("\tY = "); Serial.print(p.y);
     Serial.print("\tPressure = "); Serial.println(p.z);
      delay(100);
  }


  if (p.y>460 && p.y<660 && p.x>160 && p.x<430){
  Serial.println ("Button 1 pressed");
  previousTempValue = tempValue;
  tempValue = tempValue+1;
  delay (500); }
  if (p.y>150 && p.y<350 && p.x>160 && p.x<430){
  Serial.println ("Button 2 pressed");
  previousTempValue = tempValue;
  tempValue = tempValue-1;
  delay (500);}
  if (p.y>460 && p.y<660 && p.x>580 && p.x<850){
  Serial.println ("Button 3 pressed");
  previousHumiValue = humiValue;
  humiValue = humiValue+1;
  delay (500);}
  if (p.y>150 && p.y<350 && p.x>580 && p.x<850){
  Serial.println ("Button 4 pressed");
  previousHumiValue = humiValue;
  humiValue = humiValue-1;
  delay (500);}
}

void selectValues(){
   tft.setCursor(30,195);
   tft.setTextSize(4);
    if (tempValue != previousTempValue){
    tft.setTextColor(ILI9341_WHITE),(ILI9341_WHITE);
    tft.print(previousTempValue);
    delay(10); 
    tft.setCursor(30,195);
    tft.setTextSize(4);
   }
   tft.setTextColor(ILI9341_BLACK);
   tft.print(tempValue);
   tft.print("C");
  
   tft.setCursor(150,195);
   tft.setTextSize(4);
    if (humiValue != previousHumiValue){
    tft.setTextColor(ILI9341_WHITE),(ILI9341_WHITE);
    tft.print(previousHumiValue);
    delay(10);
    tft.setCursor(150,195);
    tft.setTextSize(4); 
   }
   tft.setTextColor(ILI9341_BLACK);
   tft.print(humiValue);
   tft.println("%"); 
   }

Either paste a snippet from a successful build
Or the complete "buildable" sketch.

I am sceptical that this line could compile:

    tft.setTextColor(ILI9341_WHITE),(ILI9341_WHITE);

But the simple answer to all your troubles is to use the full-fat method with different foreground and background colours:

    tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);    //overwrite print

If you use the same foreground and background colour it behaves like the simple

    tft.setTextColor(ILI9341_WHITE);    //transparent print

Yes, you can rub out a previous letter by printing it transparently in the background colour. But it is faster to draw in overwrite mode. You will not notice any flashes.

David.

This works perfectly David thanks for your time.

Back to square one...I have changed the font which now doesn't support foreground and background colours. The only method is to fill with a rectangle and again it flashes. Any further theories?

You don't say which library or what hardware you are using.

The Adafruit_GFX methods handle the FreeFonts in software. If it is important, they could be rendered with the hardware. However you start to lose portability between libraries.

Bodmer's libraries can handle Fonts.

Personally, I would prefer to conform to the GFX style. But I might add some of Bodmer's features.

As a simple kludge, redraw background one letter at a time instead of for the whole string.
The hardware is easier to draw foreground and background in one go. And it provides flash-free rendering.

David.

Cheers again David. Managed to sort it through code so the initial values are in the setup function and coded in an update function which only runs when any button has been pushed. This way it isn't being covered up and redrawn every cycle.

I have attached a copy of my full code just in case anyone is interested in future.
ran on Arduino mega2560

Remove the bmp draw functions if you wish to run it on a 240x320 tft.

Also worth noting it wont run unless you have an AM2315 sensor connected so maybe remove they parts aswell

protoype_latest.ino (8.54 KB)

I am a little gobsmacked. You appear to have an SPI ILI9341 display from "Adafruit_ILI9341.h".
But have a resistive Touchscreen. Perhaps it is a Seeed Studio display which has got level-shifters.

Your sensorPin = 53 implies a Mega2560.

I suggest that you look at Bodmer's libraries. I know he has a TFT_ILI9341 library.

I would use the GFX_Button class whenever possible.

Oh, and as a handy tip: press ctrl-T to format your code. It makes the world a better place !!

David.