Skip to content

Commit 8bceccf

Browse files
committed
EVENTS.md: Add ESwitch demo code.
1 parent 97d1ece commit 8bceccf

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

v3/docs/EVENTS.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,32 @@ Bound objects:
359359
2. `close` An `Event` instance. Set on contact closure.
360360
3. `open` An `Event` instance. Set on contact open.
361361

362-
Application code is responsible for clearing the `Event` instances.
362+
Application code is responsible for clearing the `Event` instances.
363+
Usage example:
364+
```python
365+
import uasyncio as asyncio
366+
from machine import Pin
367+
from primitives import ESwitch
368+
es = ESwitch(Pin("Y1", Pin.IN, Pin.PULL_UP))
369+
370+
async def closure():
371+
while True:
372+
es.close.clear()
373+
await es.close.wait()
374+
print("Closed")
375+
376+
async def open():
377+
while True:
378+
es.open.clear()
379+
await es.open.wait()
380+
print("Open")
381+
382+
async def main():
383+
asyncio.create_task(open())
384+
await closure()
385+
386+
asyncio.run(main())
387+
```
363388

364389
###### [Contents](./EVENTS.md#0-contents)
365390

0 commit comments

Comments
 (0)