have a 3.5" tough screen. In the main loop I wonder if the screen has been touched. Based on the coordinates I determine which "button" has been chosen. But when I press it once the loop won't stop, so when I print the status I get a large repose.
How can I ensure in the added code that the loop is only run through once for the selection of the "button".
Thanks for any help.
If I understand your question correctly then your problem is that you are checking to see if a button is pressed rather than checking to see if a button becomes pressed.
Here is one way to do it:
bool lastTouched;
void setup()
{
// TBD: Initialize everything here
lastTouched = ts.touched(); // make this the last line in setup()
}
void loop()
{
bool touched = ts.touched();
if (touched != lastTouched ){
lastTouched = touched;
if (touched)
{
TS_Point p = ts.getPoint();
t_y = p.x;
t_x = p.y;
pressed = true;
//Serial.printf("%03d %03d\n",p.x,p.y);
if (pressed) Serial.println(chckBtn(t_x, t_y, pressed));
}
else
{
// TBD: optional processing for when there is a transition from touched to not touched
}
}
}