I made a code based in Button test example.
It seems to select the button i "clicked", if you can test it and tell if works well for you
#include <UTFT.h>
#include<UTouch.h>
// Define Orientation of touch screen
#define TOUCH_ORIENTATION PORTRAIT
// Initialize Display
UTFT myGLCD(R61581, 38, 39, 40, 41);
// Init touchScreen
UTouch myTouch( 6, 5, 4, 3, 2);
// Fonts to use
extern uint8_t BigFont[];
int x, y;
uint32_t cx, cy;
uint32_t rx[8], ry[8];
uint32_t clx, crx, cty, cby;
float px, py;
int dispx, dispy, text_y_center;
uint32_t calx, caly, cals;
char buf[13];
void setup() {
myGLCD.InitLCD();
myGLCD.clrScr();
myGLCD.setFont(BigFont);
myTouch.InitTouch(TOUCH_ORIENTATION);
dispx=myGLCD.getDisplayXSize();
dispy=myGLCD.getDisplayYSize();
text_y_center=(dispy/2)-6;
Serial.begin(9600);
drawButton();
}
/**
* Draw two buttons
* when each button is pressed the display shows the button pressed
*/
void drawButton(){
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect (70, 10, 350, 60);
myGLCD.fillRoundRect (70, 150, 350, 210);
myGLCD.setColor(0,255,0);
myGLCD.drawRoundRect(70, 10, 350, 60);
myGLCD.drawRoundRect(70, 150, 350, 210);
myGLCD.print("Click this TEXT", 87, 27);
myGLCD.print("Or this 1", 87, 167);
}
// Read the touch
void readData(){
if(myTouch.dataAvailable()){
myTouch.read();
x = myTouch.getX();
y = myTouch.getY();
Serial.print("Lectura: "); Serial.print(x); Serial.print(" - "); Serial.println(y);
// The first button
if((x>=70 && x<=350) && (y>=10 && y<=60)){
waitForIt(70, 10, 350, 60);
}
// The second button
if((x>=70 && x<=350) && (y>=150 && y<=210)){
waitForIt(70, 150, 350, 210);
}
}
}
// Draw a red frame while a button is touched
void waitForIt(int x1, int y1, int x2, int y2)
{
myGLCD.setColor(255, 0, 0);
myGLCD.drawRoundRect (x1, y1, x2, y2);
while (myTouch.dataAvailable())
myTouch.read();
myGLCD.setColor(0, 255, 0);
myGLCD.drawRoundRect (x1, y1, x2, y2);
}
void loop() {
readData();
}