Hi, I bought one of your DS touchscreens, and have been programming just a simple reader which will take x and y co-ordinates for the point touched using the Arduino.
The screen is connected through a breakout board to four ADC pins on the Arduino (Due) 0-4 and the code I’ve written is shown below.
When I try and gather either the x-coord or the y-coord separately (ie: comment out the other function call and Serial.print lines) then I get a pretty good range of values (roughly 80 < x < 940 and 90 < y < 930).
However, when I call both functions and display both via the serial, as in the code below, the ranges are drastically smaller (47 ≤ x ≤ 53 and 937 ≤ y 968). I’d like to understand why there is such a radical difference, and if there’s anything that can be done to improve it.
Thanks in advance,
Sam
int x1 = 3; // analogue pins for touchscreen controllers
int x2 = 1;
int y1 = 0;
int y2 = 2;
int xPosition = 0;
int yPosition = 0;
void setup() {
Serial.begin(9600); //start serial communication
}
void loop() {
getXposition(); //get x-coordinate
getYposition(); //get y-coordinate
Serial.println(xPosition); //display x-coordinate
Serial.println(yPosition); //display y-coordinate
}
void getXposition() {
pinMode(14 + x1, OUTPUT);
pinMode(14 + x2, OUTPUT);
delay(1);
digitalWrite(14 + x1, HIGH);
digitalWrite(14 + x2, LOW);
delay(1);
xPosition = analogRead(y2);
}
void getYposition() {
pinMode(14 + y1, OUTPUT);
pinMode(14 + y2, OUTPUT);
delay(1);
digitalWrite(14 + y1, HIGH);
digitalWrite(14 + y2, LOW);
delay(1);
yPosition = analogRead(x1);
}