Problems while mixing pixel drawing and touchscreen point reading

I’m practicing my ILI9486 based 3.5" TFT LDC with Arduino Mega 2560 and I’m trying to create a sketch capable of painting on the TFT screen.

after including the following:

#include <UTFTGLUE.h> //use GLUE class and constructor
UTFTGLUE myGLCD(0,A2,A1,A3,A4,A0); //all dummy args
#include <stdint.h>
#include “TouchScreen.h”

code like this perfectly work:

myGLCD.clrScr();
myGLCD.setColor(255, 0, 0); // pure RED
myGLCD.drawPixel(c, r);

but after having read data from the ts class:

TSPoint p = ts.getPoint();

then myGLCD.drawPixel(c, r) no longer works.

WHY? does reading data from ts class prevent myGLCD from working?

WHY? does reading data from ts class prevent myGLCD from working?

Must be something you are doing in the code you didn't post.

Thank you PaulS.
below is the smallest sketch affected by the problem. I started from two sketches, the first initializes the screen and draws some pixels, the second one reads both position and pressure of the pencil (x, y, z) and shows the data in the serial terminal.
The merge of the two sketches shown below, allows both functions work, but after having used ts.getPoint() the drawing function stops working. Wiring is correct because the TFT screen is a rigid shield.

#include <UTFTGLUE.h> //use GLUE class and constructor
UTFTGLUE myGLCD(0,A2,A1,A3,A4,A0); //all dummy args
#include <stdint.h>
#include “TouchScreen.h”

int i;
int first_time = 0;
int x;
int d1 = 50;
int y;
int d2 = 0;

#define YP A2 // must be an analog pin, use “An” notation!
#define XM A3 // must be an analog pin, use “An” notation!
#define YM 8 // can be a digital pin
#define XP 9 // can be a digital pin

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 200);

void setup(void) {
myGLCD.InitLCD();
myGLCD.clrScr();
first_time = 1;
myGLCD.setColor(255, 0, 0); // RED
Serial.begin(9600);
}

void loop(void) {
if (first_time) {
for (i=0; i < 300; i++)
myGLCD.drawPixel(i, i); // draws a diagonal line only once, to check if it works in the loop
first_time = 0;
}
TSPoint p = ts.getPoint();
// myGLCD.drawPixel(d1++, d2++); // IF EXECUTED, DOES NOT WORK AND MAKES THE SCREEN TURN WHITE, but x, y and z continue being read and sent to the terminal.
if (p.z > ts.pressureThreshhold) {
x = p.x;
y = p.y;
myGLCD.drawPixel(x, y); // DOES NOT WORK, while still x, y, z values are read and sent to the terminal
Serial.print("X = “); Serial.print(x);
Serial.print(”\tY = “); Serial.print(y);
Serial.print(”\tPressure = "); Serial.println(p.z);
}
delay(100);
}

UTFTGLUE myGLCD(0,A2,A1,A3,A4,A0); //all dummy args
#include <stdint.h>
#include "TouchScreen.h"

int i;
int first_time = 0;
int x;
int d1 = 50;
int y;
int d2 = 0;

#define YP A2   // must be an analog pin, use "An" notation!
#define XM A3  // must be an analog pin, use "An" notation!
#define YM 8    // can be a digital pin
#define XP 9    // can be a digital pin

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 200);

If you don’t share pins between the TouchScreen instance and the UTFTGLUE instance, can you then use methods from both classes?

So, if I've well understood your hint, the point reading sketch and the drawing one that I naively copied are not aware of each other, and only work separately.... As a matter of fact they come from two collections of examples belonging to two different libraries (MCUFRIEND_kbv and Adafruit touchscreen.h ...
So I have to check the meaning of each class argument with the datasheet of the chip and unify the role of the pins. Is that conceptually correct?
I think the easiest thing to do is using the gluedemo (with the draw examples) of MCUFRIEND_kbv and replacing the ADAFRUIT touchdemo.h (for the point reading) with the one used in tounchScreen_Calibr_native included in the samples of MCUFRIEND_kbv. I've given a quick look, and they differ.....

THANKS!

Is that conceptually correct?

Yes.