Skip to content

Commit b94be59

Browse files
committed
DRIVERS.md: Add code sample for Pushbutton suppress arg.
1 parent a289cbf commit b94be59

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

v3/docs/DRIVERS.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,27 @@ the case of a single short press, `release_func` will be delayed until the
244244
expiry of the double-click timer (because until that time a second click might
245245
occur).
246246

247+
The following script may be used to demonstrate the effect of this arg. As
248+
written it assumes a Pi Pico with a pushbutton between GPIO 18 and Gnd, with
249+
the primitives installed.
250+
```python
251+
from machine import Pin
252+
import uasyncio as asyncio
253+
from primitives.pushbutton import Pushbutton
254+
255+
btn = Pin(18, Pin.IN, Pin.PULL_UP) # Adapt for your hardware
256+
pb = Pushbutton(btn, suppress=True)
257+
258+
async def main():
259+
short_press = pb.release_func(print, ("SHORT",))
260+
double_press = pb.double_func(print, ("DOUBLE",))
261+
long_press = pb.long_func(print, ("LONG",))
262+
while True:
263+
await asyncio.sleep(1)
264+
265+
asyncio.run(main())
266+
```
267+
247268
### 4.1.2 The sense constructor argument
248269

249270
In most applications it can be assumed that, at power-up, pushbuttons are not

0 commit comments

Comments
 (0)