Hi Guys,
I got the right calibration for my TFT Touchscreen. My problem is I dont know how to set the value for x and y . This my sample code:
if (myTouch.dataAvailable()) {
myTouch.read();
x=myTouch.getX(); // X coordinate where the screen has been pressed
y=myTouch.getY(); // Y coordinates where the screen has been pressed
// If we press the Distance Sensor Button
Serial.println(x); // just to view the value when pressed
delay(1000);
Serial.println(y);
delay(1000);
// THIS IS THE PART WHERE I NEED TO PUT THE RIGHT READING VALUES
if ((x>=35) && (x<=285) && (y>=90) && (y<=130)) {
drawFrame(35, 90, 285, 130); // Custom Function -Highlighs the buttons when it's pressed
currentPage = '1'; // Indicates that we are the first example
myGLCD.clrScr(); // Clears the screen
--->>> Please anyone tell me how to set the value of x and y for the touch screen. TIA
HERE ARE THE READINGS:
X Y
207 144
316 146
255 154
242 155
234 157
Leaving aside the fact that that is not actually the output from the program, what are the maximum and minimum values of X and Y returned when you touch the "button" at its extremes ?
That is what this line of code
if ((x>=35) && (x<=285) && (y>=90) && (y<=130)) {
is trying to do
You need to test whether the x and y values returned when you touch the "button" on screen are within the range of the max and min values.
How about printing the x and y values to the Serial monitor before testing them so that you can see what is going on ?
You could also test the x and y ranges separately
(x>=207) && (x<=316)
{Serial.print(x);
Serial.println(" in range");
}
and the same for y
However, as you drew the "button" in the first place you must know where it is and how big it is anyway but bear in mind that the touch function may not be returning the correct coordinates.
Please answer the question about the values of x and y when you touch each of the corners of the screen.
If the x values range from 0 to 320, then touching the same (approximate) location, and getting values that differ by 109 means that there is something wrong.
If the x values range from 0 to 32000, then touching the same (approximate) location, and getting values that differ by 109 is probably OK.