Please Help! Arduino Uno R3 Sectioning the screen surface of a 2.7 4 wire resistive touch screen

hi guys please i am having trouble understanding a part of this code, i got it off the net.
how can i relate the output to the actual dimension of my screen so that i can section the screen into 3 equal parts along Y?
i am making use of this screen.

4- Wire Touchscreen Connections
int Xresolution = 320; //62.41
int Yresolution = 240; //30.41

// Setting Touch screen connections
#define X1 A0 
#define X2 A1 
#define Y1 A2 
#define Y2 A3 

void setup()

void loop()
 int X,Y; //Touch Coordinates are stored in X,Y variable
   if(Y1>0 && Y2>0){ //After contact
   X = (analogRead(Y1))/(1024/Xresolution); //Reads X axis touch position
   if(X1>0 && X2>0){
   Y = (analogRead(X1))/(1024/Yresolution); //Reads Y axis touch position
  //Display X and Y on Serial Monitor
  if(X>0 || Y>0){  //After contact
   Serial.print("X = ");  
   Serial.print(" Y = ");

The code I’ve seen for touchscreens has some equations that take the values you get directly and translate them to the coordinates that match your screen.

Is your code printing out anything plausible as you touch the screen variously?


yes it does, can you direct me to any of those codes.
i cant find any. thanks

OK if you are getting consistent enough readings at the four corners that’s four point of a rectangle.

The desired coordinates are also four points, with the kitty-corners probably like 0, 0 and 319, 239 or whatever the maximum X and Y are for your display.

So maths. I haven’t found it plain and simple. You can just use the map function, once for each axis.



Here's some demo code, sorry I cannot determine from where it came, but it illustrates gathering the corners and making the transformation.

The equations I speak of are hidden taken care of in the map function. It's something everyone theoretical knows how to write, if you are curious the code can be found on your machine. As can any code that goes into an Arduino sketch.

# include <stdint.h>
# include <SeeedTouchScreen.h> 

# define YP A2   // must be an analog pin, use "An" notation!
# define XM A1   // must be an analog pin, use "An" notation!
# define YM 14   // can be a digital pin, this is A0
# define XP 17   // can be a digital pin, this is A3 

// Measured ADC values for (0,0) and (210-1,320-1)
// TS_MINX corresponds to ADC value when X = 0
// TS_MINY corresponds to ADC value when Y = 0
// TS_MAXX corresponds to ADC value when X = 240 -1
// TS_MAXY corresponds to ADC value when Y = 320 -1

# define TS_MINX 116*2
# define TS_MAXX 890*2
# define TS_MINY 83*2
# define TS_MAXY 913*2

//  For better pressure precision, we need to know the resistance
//  between X+ and X- Use any multimeter to read it
//  The 2.8" TFT Touch shield has 300 ohms across the X plate

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

void setup(void) {

void loop(void) {
 // a point object holds x y and z coordinates
  Point p = ts.getPoint();

// here we transform the to the screen rectangle:
  p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240);
  p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320);
 // we have some minimum pressure we consider 'valid'
 // pressure of 0 means no pressing!
  if (p.z > __PRESURE) {
     Serial.print("X = "); Serial.print(p.x); Serial.print("\tY = "); Serial.print(p.y);
     Serial.print("\tPressure = "); Serial.println(p.z);


It may not work directly with your code approach but that's the kind of thing you need to compute.