miketeachman_micropython-ro.../Examples/example_simple.py
Mike Teachman 12ee59e9c5 fixed bug where listener was not being called
listener fix:  Issue https://github.com/miketeachman/micropython-rotary/issues/15

also minor changes to Licence commenting
2022-10-31 14:46:34 -07:00

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)