Bodmer / TFT_eSPI

Arduino and PlatformIO IDE compatible TFT library optimised for the Raspberry Pi Pico (RP2040), STM32, ESP8266 and ESP32 that supports different driver chips
Other
3.83k stars 1.1k forks source link

Press event #173

Closed abdollahpour closed 6 years ago

abdollahpour commented 6 years ago

The code:

 boolean pressed = tft.getTouch(&t_x, &t_y);

returns true with an interval as long as the user keeps the figure on the screen. Is there any way to disable this behavior to create a press event?

Franciscopcosta commented 6 years ago

i am also very interested in this issue

Franciscopcosta commented 6 years ago

@Bodmer why this lib dont use the T_IRQ pin do detect if the “button” is still pressed? thanks a lot for you great job congratulations very fast lib

Bodmer commented 6 years ago

The library only provides simple detection capability, more advanced behaviors must be coed in your sketch.

A simple way to implement the behaviour you want is to create a "press" variable that reflects the last detected touch state, then a "press" event is when that variable was false but a touch is detected. So effectively you are making a "change of state" indicator.

abdollahpour commented 6 years ago

Thanks, that's exactly what I'm doing now.

Bodmer commented 6 years ago

@Franciscopcosta Adding the touch interrupt complicates matters and tends to trigger multiple times, so the approach I have used is to detect and filter the touch events via a simpler polling method.

There are other XPT2046 touch libraries that do use interrupts, so using one of those is an option if this is a "must have" feature.