ESP32 TouchPad #9622
Replies: 2 comments
-
There is no method to attach an IRQ to a TouchPad. If you use asyncio, you could create a Task which reads the TouchPad repeatedly.
Then touch GPIO32 with your finger. You'll get many callbacks (print-function) during the touch. Maybe you want to recognize only one touch, then waiting since the value is high enough (no longer touching) and then wait for the next low value (touch). The example code does not memorize the last state. Example code to with a hysteresis:
|
Beta Was this translation helpful? Give feedback.
-
Thank you for your suggestion, I was going to implement it your way of
looping if there was no other method. However I find that there is
something like this
t = TouchPad(Pin(14))t.config(500) # configure the
threshold at which the pin is considered
touchedesp32.wake_on_touch(True)
Whether this can be some how reused to call the IRQ call back.
…On Fri, 14 Oct 2022 at 21:16, Andre Müller ***@***.***> wrote:
There is no method to attach an IRQ to a TouchPad.
Currently, you have to read the value from TouchPad.
If you use asyncio, you could create a Task which reads the TouchPad
repeatedly.
import uasyncio as asyncio
from machine import Pin, TouchPad
async def async_trigger(tp: TouchPad, threshold, callback):
while True:
await asyncio.sleep(0.01)
if (value := tp.read()) < threshold:
callback(value)
async def main():
tp = TouchPad(Pin(32))
trigger_coro = async_trigger(tp, 400, print)
asyncio.create_task(trigger_coro)
while True:
await asyncio.sleep(1)
asyncio.run(main())
Then touch GPIO32 with your finger. You'll get many callbacks
(print-function) during the touch.
A synchronous function as callback could block the whole eventloop. This
is a potential problem.
Maybe you want to recognize only one touch, then waiting since the value
is high enough (no longer touching) and then wait for the next low value
(touch). The example code does not memorize the last state.
—
Reply to this email directly, view it on GitHub
<#9622 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJTPN73SGNB5ETAXWRN6GLWDF54PANCNFSM6AAAAAARFJYQ4E>
.
You are receiving this because you authored the thread.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
How do I trigger an interrupt for the TouchPad on ESP32 based on threshold values?
Beta Was this translation helpful? Give feedback.
All reactions