demo.mp4
This repository contains an example of how to read the rotation/direction from a rotary encoder and display the value on a 4-digit 7-segment display.
- Rotate left/right to adjust the counter value.
- Quickly press to clear the counter value.
- Press and hold to adjust the display brightness.
To run the example, use the following command:
cargo run -p rotary-encoder
- The current implementation may be inefficient as it pulls values on every cycle, resulting in unnecessary CPU cycles being consumed. A more efficient approach would be to utilize a timer interrupt.
- Initially, I followed this tutorial and translated the original
C
implementation toRust
. However, this approach proved to be buggy and inaccurate, as it occasionally missed rotations and miss-detected the spin direction. - Fortunately, I discovered a more accurate algorithm for rotary encoders here and subsequently found a library that implements it.