File tree 1 file changed +19
-0
lines changed 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -542,6 +542,25 @@ operations are applied is:
542
542
2 . Restrict the divided value by any maximum or minimum.
543
543
3 . Reduce modulo N if specified.
544
544
545
+ An ` Encoder ` instance is an asynchronous iterator. This enables it to be used
546
+ as follows, with successive values being retrieved with ` async for ` :
547
+ ``` python
548
+ from machine import Pin
549
+ import uasyncio as asyncio
550
+ from primitives import Encoder
551
+
552
+ async def main ():
553
+ px = Pin(16 , Pin.IN , Pin.PULL_UP ) # Change to match hardware
554
+ py = Pin(17 , Pin.IN , Pin.PULL_UP )
555
+ enc = Encoder(px, py, div = 4 ) # div mtches mechanical detents
556
+ async for value in enc:
557
+ print (f " Value = { value} " )
558
+
559
+ try :
560
+ asyncio.run(main())
561
+ finally :
562
+ asyncio.new_event_loop()
563
+ ```
545
564
See [ this doc] ( https://github.com/peterhinch/micropython-samples/blob/master/encoders/ENCODERS.md )
546
565
for further information on encoders and their limitations.
547
566
You can’t perform that action at this time.
0 commit comments