# Seeking guidance on XPT2046 Touchscreen Library, converting reported touch position to screen position

#### wwoofbum

##### New member
Using a 320 x 240 2.8" touch screen with ESP32...what is being called, by some, the CYD (Cheap Yellow Display)...I am having difficulty figuring out how to translate the position of a touch (e.g. X = 2077, Y = 2025) to the pixel position as defined by the screen (160 x 120). The (nominal) 0th x position yields a touch at ~350, the 0th y at ~450.

Sorry I don't know the CYD... Mine are mostly RED...

In some places in the code, I have simply winged it. That is I setup a sketch that echos the raw touch points and figure out MIN/MAX values.
Like in one sketch I have:
Code:
#define TS_MINX 337
#define TS_MINY 529
#define TS_MAXX 3729
#define TS_MAXY 3711

And in this case I only setup for two orientations... So I have code that just does:
Code:
#ifdef SCREEN_ORIENTATION_1
p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
#else

uint16_t px = map(p.y, TS_MAXY, TS_MINY, 0, tft.width());
p.y = map(p.x, TS_MINX, TS_MAXX, 0, tft.height());
p.x = px;
#endif

I know others like I believe @defragster had some values and maybe mappings for all 4 orientations of the display code.

You might also check on some ESP32 forum as well

As KurtE has said.

Serial.print the raw values of 2 opposite corners (you can do all 4 to get an understanding on how it works) They should be linear along each axis (some axis will count backwards depending on your screen orientation)

Then you just to map the left and right and up and down corner values to x, y screen coordinates.

Maybe the Arduino map() documentation can help?