CTRL library / Rotary encoders
Pull-down rotary encoder
This sketch demonstrates the implementation of a rotary encoder in pull-down configuration.
The code
#include <CtrlEnc.h> // Define an onTurnleft handler.void onTurnleft() { Serial.println("Pull-down rotary encoder turn left");} // Define an onTurnRight handler.void onTurnRight() { Serial.println("Pull-down rotary encoder turn right");} /* Create an encoder with: - clk signal pin. - dt signal pin. - onTurnleft handler. - onTurnRight handler. */CtrlEnc encoder(2, 3, onTurnleft, onTurnRight); void setup() { Serial.begin(9600); // For this example we use a board with internal pull-down resistors: encoder.setPinMode(INPUT_PULLDOWN); // If your board does not support that, you can use external // pull-down resistors. In that case you call the following method: // encoder.setPinMode(INPUT, PULL_DOWN);} void loop() { // Handle all rotary encoder functionality. encoder.process();}