]> vault307.fbx.one Git - ir_remote.git/blob - primitives/tests/encoder_test.py
infrared remote
[ir_remote.git] / primitives / tests / encoder_test.py
1 # encoder_test.py Test for asynchronous driver for incremental quadrature encoder.
2
3 # Copyright (c) 2021-2022 Peter Hinch
4 # Released under the MIT License (MIT) - see LICENSE file
5
6 from machine import Pin
7 import uasyncio as asyncio
8 from primitives.encoder import Encoder
9
10
11 px = Pin(33, Pin.IN, Pin.PULL_UP)
12 py = Pin(25, Pin.IN, Pin.PULL_UP)
13
14 def cb(pos, delta):
15 print(pos, delta)
16
17 async def main():
18 while True:
19 await asyncio.sleep(1)
20
21 def test():
22 print('Running encoder test. Press ctrl-c to teminate.')
23 enc = Encoder(px, py, v=0, vmin=0, vmax=100, callback=cb)
24 try:
25 asyncio.run(main())
26 except KeyboardInterrupt:
27 print('Interrupted')
28 finally:
29 asyncio.new_event_loop()
30
31 test()