Atmel AVR C++ RotaryEncoder Implementation
Arduino library to handle rotary encoders with buttons as a user input device. Arduino RotaryEncoder with Button Implementation.
Encoder and button can be connected to any input pin, as this library requires it's timer interrupt service routine ClickEncoder:service() to be called every millisecond. The example uses TimerOne for that.
The library supports acceleration, so when the encoder is rotated faster, the encoders value will increment faster.
Acceleration can be enabled or disabled at runtine using
For instance, it makes sense to disable acceleration when entering a configuration menu that will be navigated using the encoder.
Please note that the acceleration parameters have been tuned for 1ms timer intervals, and need to be changed if you decide to call the service method in another interval. (You'd need to increase ENCACCELINC and ENCACCELINC).
Depending on the type of your encoder, you can define use the constructors parameter
stepsPerNotchan set it to either
4steps per notch, with
1being the default.
If you have trouble with certain encoders, try
#define ENC_DECODER (1 << 2)
to use a table-based decoder, which can then be tuned using
The default is ENC_HALFSTEP 1.
The Button reports multiple states:
Released. You can fine-tune the timings in the library's header file.
If your encoder does not have a button, and you need to save program memory, use
#define WITHOUT_BUTTON 1prior including
ClickEncoder.h, and ignore the third parameter
BTNof the constructor.