TFT 2.8 Not retrieving current X,Y,Z position

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
gosbrut
 
Posts: 74
Joined: Thu Feb 20, 2014 5:36 pm

TFT 2.8 Not retrieving current X,Y,Z position

Post by gosbrut »

Hey,
Impossible to get trusted cursor position.
Following code
void loop() {
if (ts.touched()) {
Serial.println("This is printed repeatedly.");
TS_Point p = ts.getPoint();
// p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
// p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
tft.fillRoundRect(25,95,300,300, 2, RED);
delay(50);
tft.setCursor(30,100);
tft.print(String(p.x)+ ":" + String(p.y) + ":p:" + String(p.z)); //tft.print();

}
delay(100);
}


See the results at the video I uploaded: http://youtu.be/8dBUSFnw594

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: TFT 2.8 Not retrieving current X,Y,Z position

Post by adafruit_support_mike »

Your code has the map() statements commented out. What happens if you uncomment them?

gosbrut
 
Posts: 74
Joined: Thu Feb 20, 2014 5:36 pm

Re: TFT 2.8 Not retrieving current X,Y,Z position

Post by gosbrut »

Hei, the comment are inf¡different , as you can see in the video
If i use the map, then the same effect, well with mapped values to 320x240, but same results.

This code is best but same unreliabl results,
Aparently the problem is at follow:

If i press only 1 time then ok, results are fine, but,
if i press the finger lets say during 2 seconds ( i get e.g,. coords, 50,50), then move my finger to other position then i get old results (50,50), and i must wait 2 or 3 seconds for get new coords (e.g. 120,150)

Solution ?

void loop() {
if (!ts.bufferEmpty()) {
TS_Point p = ts.getPoint();
p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
if (ts.touched()) {
tft.fillRoundRect(50,195,tft.width() - 50, tft.height() - 195, 2, BLACK);
delay(50);
tft.setCursor(60,200);
tft.setTextSize(2);
tft.setTextWrap(false);
tft.print(String(p.x) + ":" + String(p.y));
}

}

}

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: TFT 2.8 Not retrieving current X,Y,Z position

Post by adafruit »

The STMPE buffers all reads in a FIFO (this is a benefit, so you can catch touches if they happened between queries), however, that means you have to read thru the entire buffer to get the latest data. bufferSize() will let you know how many points are stored

User avatar
aerouta
 
Posts: 25
Joined: Wed Jan 02, 2013 12:39 pm

Re: TFT 2.8 Not retrieving current X,Y,Z position

Post by aerouta »

How do you read the last point in the buffer. I have seen a few questions on this but no clear answer.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: TFT 2.8 Not retrieving current X,Y,Z position

Post by adafruit_support_mike »

This should work:

Code: Select all

TSPoint p;
while ( ! ts.bufferEmpty() ) {
    p = ts.getPoint();
}

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”