Sample code for rotary encoder handling that I've found seems to double step with my encoder. I guess there's other that have half steps or something. Anyhow, here's how I've been doing it and it's working just fine.
CLKPin.irq(trigger=Pin.IRQ_FALLING, handler=rotary_callback)
def rotary_callback(pin):
"""Interrupt handler for rotary encoder falling edge"""
global frequency
if DTPin.value() == 1:
frequency += int(math.pow(10, step_power))
else:
frequency -= int(math.pow(10, step_power))
setFrequency(frequency)
So, the interrupt triggers just on the falling edge of the clock pin and then looks to see if the data pin is high (for clockwise) or low (counter-clockwise).
A full project is stored here.
No comments:
Post a Comment