No pressure detected ILI9341

Hello! Im trying to make a program with an LCD screen, and Im having trouble when it comes to detecting when the user touches the screen. I’ve seen some examples and tried to copy some stuff from them but I keep getting “0” at p.z.

Im 100% sure that the problem is in the code and not in the screen cause the examples work perfectly. Also Im new in programming with Arduino and I find it really difficult to find documentation about some stuff, for example with the TouchScreen library.

I’ll paste my code here:

#include <TouchScreen.h>
#include <LCDWIKI_GUI.h>
#include <LCDWIKI_KBV.h>

LCDWIKI_KBV myScreen(ILI9341,A3,A2,A1,A0,A4); 

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

//param calibration from kbv
#define LT 96
#define RT 874
#define TOP 839
#define BOT 193

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

#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

void drawHome(){
  int w;
  w = myScreen.Get_Display_Width();
  myScreen.Set_Draw_color(255,255,255);
  myScreen.Draw_Fast_HLine(0, 25, w);
  myScreen.Set_Text_colour(WHITE);
  myScreen.Set_Text_Back_colour(BLACK);
  myScreen.Set_Text_Size(3);
  myScreen.Print_String("01/07/2020", LEFT, 0);
  myScreen.Print_String("00:00", RIGHT, 0);
  myScreen.Print_String("Riego", CENTER, 30);
  for (int i = 0; i < 4; i++){
    myScreen.Draw_Rectangle(12*(i+1) + i * 65, 210, 12*(i+1) + (i+1) * 65, 230);
  }
}

void screen0(){
  myScreen.Fill_Screen(BLUE);
}

void screen1(){
  myScreen.Fill_Screen(RED);
}

void screen2(){
  myScreen.Fill_Screen(GREEN);
}

void screen3(){
  myScreen.Fill_Screen(YELLOW);
}

void setup() {
  Serial.begin(9600);
  myScreen.Init_LCD();
  myScreen.Set_Rotation(1);
  myScreen.Fill_Screen(BLACK);
  myScreen.Set_Text_Mode(0);
  drawHome();
  pinMode(13, OUTPUT);
}

#define MINPRESSURE 10
#define MAXPRESSURE 1000

void loop() {
  int x, y;
  int screen = -1;
comme:
  digitalWrite(13, HIGH);
  TSPoint p = ts.getPoint();
  digitalWrite(13, LOW);
  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
  digitalWrite(YP, HIGH);
  digitalWrite(XM, HIGH);
  
  if (screen != -1){
    switch(screen){
      case 0:
        screen0();
        break;
      case 1:
        screen1();
        break;
      case 2:
        screen2();
        break;
      case 3:
        screen3();
        break;
    }
  }
  Serial.println(p.z);
  if (p.z > MINPRESSURE && p.z < MAXPRESSURE){
    Serial.println(p.z);
    x = map(p.x, LT, RT, 0, myScreen.Get_Display_Width());
    y = map(p.y, TOP, BOT, 0, myScreen.Get_Display_Height());
    if (y < 230 && y > 210){
      if (x > 12 && x < 77)
        screen = 0;
      else if (x > 89 && x < 154)
        screen = 1;
      else if (x > 166 && x < 231)
        screen = 2;
      else if (x > 243 && x < 308)
        screen = 3;
      goto comme;
    }
  }
}

I dont really understand things like why I need lines like this one: “digitalWrite(YP, HIGH)”, as I really cant find useful information in google.

Thanks for the help!

goto :o :o ? Why don’t you write this the normal way to let the loop do it’s work ?

Can you share the link to the library you are using?

Seems you copied some crappy code from somewhere...Get rid of

 pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
  digitalWrite(YP, HIGH);
  digitalWrite(XM, HIGH);

have you seen this in any of the examples ?