mirror of
https://github.com/miketeachman/micropython-rotary.git
synced 2024-11-13 19:47:49 +00:00
12ee59e9c5
listener fix: Issue https://github.com/miketeachman/micropython-rotary/issues/15 also minor changes to Licence commenting
36 lines
840 B
Python
36 lines
840 B
Python
# MIT License (MIT)
|
|
# Copyright (c) 2021 Mike Teachman
|
|
# https://opensource.org/licenses/MIT
|
|
|
|
# example for MicroPython rotary encoder
|
|
|
|
import sys
|
|
if sys.platform == 'esp8266' or sys.platform == 'esp32':
|
|
from rotary_irq_esp import RotaryIRQ
|
|
elif sys.platform == 'pyboard':
|
|
from rotary_irq_pyb import RotaryIRQ
|
|
elif sys.platform == 'rp2':
|
|
from rotary_irq_rp2 import RotaryIRQ
|
|
else:
|
|
print('Warning: The Rotary module has not been tested on this platform')
|
|
|
|
import time
|
|
|
|
|
|
r = RotaryIRQ(pin_num_clk=13,
|
|
pin_num_dt=14,
|
|
min_val=0,
|
|
max_val=5,
|
|
reverse=False,
|
|
range_mode=RotaryIRQ.RANGE_WRAP)
|
|
|
|
val_old = r.value()
|
|
while True:
|
|
val_new = r.value()
|
|
|
|
if val_old != val_new:
|
|
val_old = val_new
|
|
print('result =', val_new)
|
|
|
|
time.sleep_ms(50)
|