Can't overwrite text on my touchscreen display

I'm using MCUFriend_kbv libraries to write to my touch screen, but when I try to overwrite existing text on the screen, it simply doesn't work. and after many loops, I start getting artifacts on the display (as shown in the attached image). The area I'm trying to clear - for now - is inside the blue rectangle. The full sketch is attached.
Here's the relevant code:

void UpdateIntTempDisplay()
{
  Serial.print("\n\tUpdated Interior Temp is: ");
  Serial.println(*pCurrentIntTemp);
  //tft.fillRect(210, 50, 35, 60, DARKGRAY); //clear the area with the background color (I tried this first and it didn't work)
  tft.setCursor(215, 55);
  tft.setTextColor(DARKGRAY,DARKGRAY);
  tft.print("  ");
  tft.setCursor(215, 55);
  tft.setTextColor(WHITE,DARKGRAY);
  tft.setTextSize(2);
  tft.print(*pCurrentIntTemp);
}

944_climate_control.ino (21.3 KB)

  tft.setTextColor(DARKGRAY,DARKGRAY);

When you set foreground colour equal to the background colour GFX treat this as transparent text. i.e. the same as saying tft.setTextColor(DARKGRAY);

If you want to draw a fresh background, use a different colour for the background argument.

David.

You're awesome David. Thanks! Also, thanks for writing the MCUFriend_kbv library. I was pulling my hair out trying to figure out why I couldn't get anything on screen until I found your post.

Hrm, It seems like the overwrite only works twice, then I start getting weird artifacts and the number doesn't get overwritten. Do I have to clear the whole buffer after x overwrites?

I updated the code to be as follows:

void UpdateIntTempDisplay()
{
  Serial.print("\n\tUpdated Interior Temp is: ");
  Serial.println(*pCurrentIntTemp);
  tft.setCursor(215, 55);
  tft.setTextColor(DARKGRAY,WHITE);
  tft.print("       "); //Yes, this generates some extra white background, but for debugging I can live with it
  tft.setCursor(215, 55);
  tft.setTextColor(WHITE,DARKGRAY);
  tft.setTextSize(2);
  tft.print(*pCurrentIntTemp);
}

in the attached image, you can see the white pixels showing up in the red fill circle and around the current temp value.

Paste or attach the whole INO file. Then we can see what is happening.

Here ya go, thanks for your time.

944_climate_control.ino (21.4 KB)

Figured it out, I had a PWM signal going out on one of the LCD pins.

Since all the PWM pins on a mega are taken up by the shield, does that mean I need to use a one of the 40 pins at the “bottom” of the board to drive another arduino to output the PWM signal I need for my device?

Yes, the TFT uses 2-9 for the data bus. 10-13 are normally used for the microSD card.

Since you are not using SD from the Shield, you can use 10-13 as PWM pins. However they will be difficult to access with the Shield plugged in.

44-46 can be used as PWM from the 18x2 header.

Didn't realize the 44-46 could do that, thanks again!

Nor did I. I never use the MEGA2560.

Download and print one of the MEGA2560 pinout diagrams.

David.