Рет қаралды 3,912
Have you been fighting with bounce and rotary encoders in your Arduino project?
Well I have!
This little video shows how to use Keyed Rotary Encoders in Arduino Code.
This is a the encoder: www.aliexpress...
The idea is that when the key is pressed, the arduino will start counting encoder ticks, positive clockwise, or negative counter-clockwise. The display is updated on change in counts.
Since these encoders have built in hardware debouncing, no need to play around with delays and so on.
The code uses the C-preprocessor to generate method definitions for the 10 sets of interrupt handlers needed.
For a given encoder:
1. set an interrupt handler to fire on key pin falling edge:
- this handler sets an interrupt handler on falling edge for the encoder S1 pin, as well as a new handler for the rising edge of key pin.
2. the S1 falling edge handler looks at S2 and increments or decrements the tick count,
3. the risinge edge key pin handler unsets the handler on S1 and resets the falling edge handler fo the key pin.
The 5 encoder code as well as a simpler single encoder version is available in my repo: gitlab.com/gra...