- Polling for the value of the pins: write a loop that reads the value of channel A and channel B and compare with previous value. NOT APPEALING. The processor is in an infinite loop.
- Have channel A interrupt on the falling edge and read the value of channel B. MORE APPEALING. The processor only works when it needs to. (Note: Arduino can handle two external interrupts and can be set as interrupting on a falling edge). Disadvantage: there is a falling edge every two clicks. This solution works at half the resolution of the encoder.
- Have channel A and B interrupt and read the value of the other channel. MORE APPEALING. With two interrupts, you can read the encoder at full resolution. Disadvantage: since Arduino can only handle two external interrupts, you can only attach a single encoder to the board.
Saturday, March 21, 2009
How to Read Rotary Encoder (I)
Connect the Channel A pin and the Channel B pin of a rotary encoder into two Arduino inputs. Then there are several ways to read the encoder:
No comments:
Post a Comment