How to supply the right coordinates for a button to work? (TFT/Adafruit)

#include <Adafruit_TFTLCD.h>
#include <TouchScreen.h>
#include <Adafruit_GFX.h>

// define the pins used to communicate with the display
#define LCD_CS   A3
#define LCD_CD   A2
#define LCD_WR   A1
#define LCD_RD   A0
#define LCD_RESET   A4

#define TS_MINX 122
#define TS_MINY 111
#define TS_MAXX 942
#define TS_MAXY 890

#define YP A3
#define XM A2
#define YM 9
#define XP 8

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

// create an instance of the TFT display object
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

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

boolean buttonEnabled = true;

void setup() {
  Serial.begin(11520);
  firstPage(); // draw the first page
}

void loop() {
  TSPoint p = ts.getPoint();
  
  if (p.z > ts.pressureThreshhold) {
    
   p.x = map(p.x, TS_MAXX, TS_MINX, 0, 320);
   p.y = map(p.y, TS_MAXY, TS_MINY, 0, 480);
       
   if(p.x > 20 && p.x < 60 && p.y > 80 && p.y < 160){
    
    buttonEnabled = true;
    
    pinMode(XM, OUTPUT);
    pinMode(YP, OUTPUT);
    
    tft.fillScreen(BLUE);
    
    tft.setCursor(30,30);
    tft.setTextColor(YELLOW);
    tft.setTextSize(3);
    tft.print("ADOBO");
    
    tft.setCursor(30,60);
    tft.setTextColor(WHITE);
    tft.setTextSize(3);
    tft.print("Php 60.00");    

    tft.setCursor(30,100);
    tft.setTextColor(YELLOW);
    tft.setTextSize(3);
    tft.print("Your Balance:");

    tft.setCursor(30,130);
    tft.setTextColor(WHITE);
    tft.setTextSize(3);
    tft.print("Php 500.00"); 
    
    tft.fillRect(190,180, 100, 40, RED);
    tft.drawRect(190,180,100,40,WHITE);
    tft.setCursor(225, 193);
    tft.setTextColor(WHITE);
    tft.setTextSize(2);
    tft.print("PAY");        

    tft.fillRect(30,180, 100, 40, BLUE);
    tft.drawRect(30,180,100,40,BLACK);
    tft.setCursor(45,193);
    tft.setTextColor(WHITE);
    tft.setTextSize(2);
    tft.print("RETURN");
  }      
 }
}

void firstPage() {
  tft.reset();
  uint16_t identifier = tft.readID();
  tft.begin(identifier);
  tft.setRotation(1);
  tft.fillScreen(BLUE);

  tft.setCursor(190,30);
  tft.setTextColor(YELLOW);
  tft.setTextSize(4);
  tft.print("MENU");

  tft.setCursor(20,40);
  tft.setTextColor(YELLOW);
  tft.setTextSize(1);
  tft.print("04/18/2023");

  tft.setCursor(20,30);
  tft.setTextColor(YELLOW);
  tft.setTextSize(1);
  tft.print("HELL TUESDAY");

  tft.fillRect(20,80, 80, 40, MAGENTA);
  tft.drawRect(20,80,80,40,BLACK);
  tft.setCursor(30,95);
  tft.setTextColor(WHITE);
  tft.setTextSize(1);
  tft.print("ADOBO");

  tft.fillRect(110,80, 80, 40, MAGENTA);
  tft.drawRect(110,80,80,40,BLACK);
  tft.setCursor(120,95);
  tft.setTextColor(WHITE);
  tft.setTextSize(1);
  tft.print("SINIGANG");

  tft.fillRect(200,80, 80, 40, MAGENTA);
  tft.drawRect(200,80,80,40,BLACK);
  tft.setCursor(210,95);
  tft.setTextColor(WHITE);
  tft.setTextSize(1);
  tft.print("TULINGAN");

  tft.fillRect(20,180, 80, 40, MAGENTA);
  tft.drawRect(20,180,80,40,BLACK);
  tft.setCursor(30,195);
  tft.setTextColor(WHITE);
  tft.setTextSize(1);
  tft.print("SIOMAI");

  tft.fillRect(110,180, 80, 40, MAGENTA);
  tft.drawRect(110,180,80,40,BLACK);
  tft.setCursor(120,195);
  tft.setTextColor(WHITE);
  tft.setTextSize(1);
  tft.print("MENUDO");

  tft.fillRect(200,180, 80, 40, MAGENTA);
  tft.drawRect(200,180,80,40,BLACK);
  tft.setCursor(210,195);
  tft.setTextColor(WHITE);
  tft.setTextSize(1);
  tft.print("TINOLA");

  tft.fillRect(20,130, 80, 40, MAGENTA);
  tft.drawRect(20,130,80,40,BLACK);
  tft.setCursor(30,145);
  tft.setTextColor(WHITE);
  tft.setTextSize(1);
  tft.print("CHICKEN");

  tft.fillRect(110,130, 80, 40, MAGENTA);
  tft.drawRect(110,130,80,40,BLACK);
  tft.setCursor(120,145);
  tft.setTextColor(WHITE);
  tft.setTextSize(1);
  tft.print("AFRITADA");

  tft.fillRect(200,130, 80, 40, MAGENTA);
  tft.drawRect(200,130,80,40,BLACK);
  tft.setCursor(210,145);
  tft.setTextColor(WHITE);
  tft.setTextSize(1);
  tft.print("KARE-KARE");  
}

The void loop() contains the button function, but somehow I cannot supply the right coordinates for it to work on the appropriate box. How should I supply the right coordinates using the coordinates from the void firstScreen()?

did this demo a while back maybe it will help..

ESPTouch

have fun.. ~q

Can you apply that only with Arduino UNO?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.