interrupts
# help
m
Hi all, I am trying to implement interrupts on the A and B pins of a rotary encoder. I can't find any documentation on this, help please.
f
Toit doesn't give direct access to interrupts. If you just want to wait for a pin to change you would generally use
pin.wait_for
. However, for a rotary encoder that would probably be too slow. I think the pulse_counter library is what you are looking for: https://libs.toit.io/pulse_counter/library-summary
That peripheral automatically counts pulses for you. I'm not too familiar with rotary encoders, though. So maybe that doesn't work.
m
Mmm, rotary encoders rely on the relationship of Pin A and Pin B. There are usually four possible stable states. which indicate the direction of rotation.
I will try the pulse counter as I have an upcoming project anyway.
f
The pulse counter has one pin to count and another as control pin for the direction.
m
Ok, that may work, i'll investigate.
a
two years later -- but in case it's helpful, I implemented an algorithm for a rotary encoder using a pulse counter: https://github.com/aschober/toit-m5stack-dial/blob/260e496420361ef2f15b6247567bffbabfc3b913/src/m5stack_dial.toit#L166-L226
k
👌🏻 Thank you