Arduino Example Snippet
#include <RotaryEncoder.h>
#define PIN_BT 1
#define PIN_CL 14
#define PIN_DT 41
RotaryEncoder encoder(PIN_CL, PIN_DT, RotaryEncoder::LatchMode::TWO03);
void setup() {
Serial.begin(9600);
pinMode(PIN_BT, INPUT);
}
void loop() {
static int pos = 0;
encoder.tick();
if (digitalRead(PIN_BT) == HIGH) {
Serial.println("Button Press");
delay(100);
}
int newPos = encoder.getPosition();
if (pos != newPos) {
Serial.print("pos:");
Serial.print(newPos);
Serial.print(" dir:");
Serial.println((int)(encoder.getDirection()));
pos = newPos;
}
}