Hello,
I am using Arduino UNO with 2.8 tft shield.
I wrote down the following code:
void loop(void) {
TSPoint p = ts.getPoint();
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
Serial.print("X = "); Serial.print(p.x);
Serial.print("\tY = "); Serial.print(p.y);
Serial.print("\tPressure = "); Serial.println(p.z);
tft.setTextSize(2);
tft.setCursor(50, 100);
tft.println("Hello...");
delay(1000);
}
}
I have the following problem: during the loop SERIAL MONITOR shows the values of p.x, p.y and p.z, but the system doesn't print on the display "Hello..." in position (50,100).
If I move the lines
tft.setTextSize(2);
tft.setCursor(50, 100);
tft.println("Hello...");
delay(1000)
outside the IF statement than it works.
I initialized the display in the right way because in the setup phase (code not reported) it works and write in the display what I want in the right position.
Thank you very much in advance.
LP
Please post a link to the actual screen that you have bought.
If it is a regular "Blue 2.8 inch" Mcufriend shield, the Touch panel shares pins with the TFT pins.
TSPoint p = ts.getPoint();
pinMode(XM, OUTPUT); //if pins are shared
pinMode(YP, OUTPUT);
...
David.
Thank you very much for your reply!
Here the pictures you requested.
Adding the lines to fix the behavior due to shared pins
// if sharing pins, you'll need to fix the directions of the touchscreen pins
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
void loop(void) {
TSPoint p = ts.getPoint();
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
Serial.print("X = "); Serial.print(p.x);
Serial.print("\tY = "); Serial.print(p.y);
Serial.print("\tPressure = "); Serial.println(p.z);
//
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
//
tft.setTextSize(2);
tft.setCursor(50, 100);
tft.println("Hello...");
delay(1000);
}
}
nothing happens. It doesn't write "Hello...'. May be I put the lines in a wrong position...
Yes. I showed you where to place the pinMode() lines.
You have put them inside the if() block.
When the if() condition fails, it has still called getPoint() but it misses the pinMode()
Seriously. Try ctrl-T to format your code. It makes your blocks easy to read. And it becomes obvious which lines get executed.
David.
Ok thank you David, very kind!