On the number pad, I press "1" and it will register the number 3" and vice versa, however, the numbers in the center of the pad work normal, so It could be the Y or X axis are reversed.
I attached a picture of the number pad to give a better illustration.
I'm using a Kuman UNO R3 2.8 inch TFT and an Elegoo MEGA 2560 R3 Board
Go on. I can't believe humans can ever understand stuff like this:
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
// scale from 0->1023 to tft.width
p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0);
p.y = map(p.y, TS_MINY, TS_MAXY, tft.height(), 0);
Serial.print("("); Serial.print(p.x); Serial.print(", ");
Serial.print(p.y); Serial.print(", ");
Serial.print(p.z); Serial.println(") ");
}
Surely it is more intuitive to calibrate in terms of TS_LEFT and TS_RIGHT
and then say:
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
// scale from 0->1023 to tft.width
pixel_x = map(p.x, TS_LEFT, TS_RIGHT, 0, tft.width()); //map left->right as 0-239
pixel_y = map(p.y, TS_TOP, TS_BOT, 0, tft.height()); //map top->bot as 0-319
Serial.print("("); Serial.print(pixel_x); Serial.print(", ");
Serial.print(pixel_y); Serial.print(", ");
Serial.print(p.z); Serial.println(") "); //pressure
}
David.
I tried it out and it gave me this error
exit status 1
'pixel_x' was not declared in this scope
Of course it will. I just invented a descriptive name out of nowhere.
You would need to declare the variables e.g.
int pixel_x, pixel_y; //declare the variables before they are used
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
// scale from 0->1023 to tft.width
pixel_x = map(p.x, TS_LEFT, TS_RIGHT, 0, tft.width()); //map left->right as 0-239
pixel_y = map(p.y, TS_TOP, TS_BOT, 0, tft.height()); //map top->bot as 0-319
...
My main point was to say that TS_MINX is a silly concept.
You want to think about LEFT and RIGHT. Sometimes LEFT will be less than RIGHT. Other Touch panels might have LEFT more than RIGHT.
You want to map LEFT and RIGHT to pixel X coordinates. You just put in your calibration values and the map() fuction does the correct transformation.
David.
How do you derive the calibration values?
By running a Calibration sketch.
David.