Thought I’d share this code, which might help de-mystify the inards of a rotary encoder. It’s not intended as a real-life solution- there are libraries for that and interrupts seems to be the way to go. It’s more of a tutorial so you can see how the 2 outputs vary as the encoder is rotated.
- A snippet from the EC11 datasheet. It shows there are 2 detents (detent = click stop) per cycle but mine only has one.
- My schematic
- Sketch encoder_v3 which just uses 2x LEDs to indicate the pins’ status, and it also prints an A, a, B and b depending on that status. You have to turn very slowly between detents to see these.
- Sketch encoder_v4 which counts the cycles, taking account of direction, and prints where you are.
Use it, don’t use it 8). As always, YMMV.
encoder_v3.ino (1.75 KB)
encoder_v4.ino (3.57 KB)