A rotary encoder class library for Arduino. Encoder events are returned as an enum. Both clockwise and anti-clockwise rotations trigger events. The encoder can be rotated at three rates with unique enum entries being returned for each. This means you can use the encoder for both fine and coarse control of a power supply voltage for example. The class also handles button presses and recognises held down buttons and double-clicks. The rotation rates and button press timings are tunable. See Encoder.h
for available class methods.
See Encoder.ino
for a very basic example program.
- Place
#include "Encoder.h"
at the top of the.ino
file. - Create a global Encoder variable.
- Initialise the encoder with
init()
inside thesetup()
function. - Regularly poll the encoder to check its state. The best way is to attach the pins as change interrupts and call
poll()
when an interrupt is triggered. If this isn't possible, just be sure to callpoll()
regularly in the mainloop()
function. - Events are returned as an enum. See example for use.