3.2 TFT display with Adafruit GFX problem/bug?

Hey so i'm using this display with Adafruit GFX and TouchScreen libraries + MCUFRIEND library.

Heres my project code:

`#include <stdint.h>
#include "TouchScreen.h"
#include <Adafruit_GFX.h>    // Core graphics library
#include <MCUFRIEND_kbv.h>
#include <Fonts\FreeSans18pt7b.h>
#include <Fonts\FreeSansBold24pt7b.h>
MCUFRIEND_kbv tft;

// TFT Breakout  -- Arduino UNO / Mega2560 / OPEN-SMART UNO Black
// GND              -- GND
// 3V3               -- 3.3V
// CS                 -- A3
// RS                 -- A2
// WR                -- A1
// RD                 -- A0
// RST                -- RESET
// LED                -- GND
// DB0                -- 8
// DB1                -- 9
// DB2                -- 10
// DB3                -- 11
// DB4                -- 4
// DB5                -- 13
// DB6                -- 6
// DB7                -- 7

// Assign human-readable names to some common 16-bit color values:
#define  BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
#define MINPRESSURE 10
#define MAXPRESSURE 1000

uint16_t g_identifier;
uint8_t YP = A1;  // must be an analog pin, use "An" notation!
uint8_t XM = A2;  // must be an analog pin, use "An" notation!
uint8_t YM = 7;   // can be a digital pin
uint8_t XP = 6;   // can be a digital pin
uint16_t pLEFT = 880;
uint16_t pRIGHT  = 170;
uint16_t pTOP = 950;
uint16_t pBOTTOM = 180;
int v1;
uint16_t xpos, ypos; 
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

void setup() {
tft.reset();
Serial.begin(9600);
uint16_t g_identifier = tft.readID();
tft.begin(g_identifier);
tft.setRotation(1);
randomSeed(analogRead(0));
homeScreen();
}

void homeScreen(){  
  v1 = random(0, 2);
  tft.fillScreen(WHITE); 
  tft.setFont(&FreeSansBold24pt7b);
  tft.setTextColor(BLACK);
  if (v1 ==0){
  tft.setCursor(90,65);
  tft.print("Welcome!");
  }
  else if (v1 == 1){
  tft.setCursor(135,65);
  tft.print("Hello!");
  }

   tft.drawLine(20, 85, 380, 85, BLACK);
   tft.fillRoundRect(150, 100, 100, 100, 20, BLACK);
   tft.fillRoundRect(157, 107, 86, 86, 15, WHITE);
   tft.fillTriangle(175, 180, 175, 120, 225, 150, BLACK);
   playTouch();
}

int returnX(int x){
  
}

int waitUntil=1;
void playTouch(){
    do {
    TSPoint p = ts.getPoint();
    xpos = map(p.x, pLEFT, pRIGHT, 0, tft.width());
    ypos = map(p.y, pTOP, pBOTTOM, 0, tft.height());
    if ( p.z > MINPRESSURE && p.z < MAXPRESSURE && xpos<250 && xpos>150 && ypos>100 && ypos<200 ){
    Serial.print("X = "); Serial.print(p.x);
    Serial.print("\tY = "); Serial.print(p.y);
    Serial.print("\tPressure = "); Serial.println(p.z);
    //tft.fillRoundRect(150, 100, 100, 100, 20, GREEN);
    lockScreen();
    }
   } 
    while (waitUntil<2); 
    
}
void lockScreen(){
  waitUntil=3;
  tft.setCursor(0,0);
  tft.print("very weird bug");
  tft.fillScreen(RED);
  Serial.print("Got to lockScreen()");
  tft.setCursor(90,65);
  tft.setTextColor(BLACK);
  tft.setFont(&FreeSans18pt7b);
  tft.print("Please Enter Fingerprint");
  tft.drawLine(20, 80, 280, 80, BLACK);
  
}


void loop() {

    }`

Everything is pretty much working, but after i detect the play button touch and jump to the lock screen (lockScreen()) nothing renders, not the text, background or lines. it just show a blank white display. (Added a video)

ezgif-2-e775213b4196

Any help would be much appreciated.

Please read the examples that come with the library e.g. touch_shield_new.ino

    uint16_t xpos, ypos;  //screen coordinates
    tp = ts.getPoint();   //tp.x, tp.y are ADC values

    // if sharing pins, you'll need to fix the directions of the touchscreen pins
    pinMode(XM, OUTPUT);
    pinMode(YP, OUTPUT);
    // we have some minimum pressure we consider 'valid'
    // pressure of 0 means no pressing!

On Mcufriend Uno Shields the Touch pins are shared with the TFT pins. Which means that you must use pinMode()

Look at the next lines in the example. It shows you how to calculate the x, y pixel coordinates for different screen rotations.

David.

Thank you very much it works now!
So if i want to use the touch again, will the pinMode change automatically to INPUT or i should change it again manually?

Historically, the TouchScreen.h library reads ADC values from the Touch Pins (after setting to INPUT)
However, it does not restore the mode afterwards.

The TFT library does not expect its data and control pins to have changed mode.

It would be quite possible for TouchScreen.h library to restore the Touch pins' mode. However it does not. It is up to the User.

David.