@@ -24,6 +24,7 @@ goes outside defined bounds.
24
24
4.1 [ Pushbutton class] ( ./DRIVERS.md#41-pushbutton-class )
25
25
  ;  ;  ;  ;  ; 4.1.1 [ The suppress constructor argument] ( ./DRIVERS.md#411-the-suppress-constructor-argument )
26
26
  ;  ;  ;  ;  ; 4.1.2 [ The sense constructor argument] ( ./DRIVERS.md#412-the-sense-constructor-argument )
27
+ 4.2 [ ESP32Touch class] ( ./DRIVERS.md#42-esp32touch-class )
27
28
5 . [ ADC monitoring] ( ./DRIVERS.md#5-adc-monitoring ) Pause until an ADC goes out of bounds
28
29
5.1 [ AADC class] ( ./DRIVERS.md#51-aadc-class )
29
30
5.2 [ Design note] ( ./DRIVERS.md#52-design-note )
@@ -321,6 +322,42 @@ the `closed` state of the button is active `high` or active `low`.
321
322
See [ Advanced use of callbacks] ( ./DRIVERS.md#8-advanced-use-of-callbacks ) for
322
323
ways to retrieve a result from a callback and to cancel a task.
323
324
325
+ ## 4.2 ESP32Touch class
326
+
327
+ This subclass of ` Pushbutton ` supports ESP32 touchpads providing a callback
328
+ based interface. See the
329
+ [ official docs] ( http://docs.micropython.org/en/latest/esp32/quickref.html#capacitive-touch ) .
330
+
331
+ API and usage are as per ` Pushbutton ` with the following provisos:
332
+ 1 . The ` sense ` constructor arg is not supported.
333
+ 2 . The ` Pin ` instance passed to the constructor must support the touch
334
+ interface. It is instantiated without args, as per the example below.
335
+ 3 . There is an additional class variable ` sensitivity ` which should be a float
336
+ in range 0.0..1.0. The value ` v ` returned by the touchpad is read on
337
+ initialisation. The touchpad is polled and if the value drops below
338
+ ` v * sensitivity ` the pad is assumed to be pressed.
339
+
340
+ Example usage:
341
+ ``` python
342
+ from machine import Pin
343
+ from primitives import ESP32Touch
344
+ import uasyncio as asyncio
345
+
346
+ async def main ():
347
+ tb = ESP32Touch(Pin(15 ), suppress = True )
348
+ tb.press_func(lambda : print (" press" ))
349
+ tb.double_func(lambda : print (" double" ))
350
+ tb.long_func(lambda : print (" long" ))
351
+ tb.release_func(lambda : print (" release" ))
352
+ while True :
353
+ await asyncio.sleep(1 )
354
+
355
+ asyncio.run(main())
356
+ ```
357
+ If a touchpad is touched on initialisation no callbacks will occur even when
358
+ the pad is released. Initial button state is always ` False ` . Normal behaviour
359
+ will commence with subsequent touches.
360
+
324
361
###### [ Contents] ( ./DRIVERS.md#1-contents )
325
362
326
363
# 5. ADC monitoring
0 commit comments