#include <Encoder.h>
#define A_PIN 2
#define B_PIN 3
Encoder rotary(A_PIN, B_PIN);
#define rstbtn 4 // reset button
long counter = 0;
void setup() {
pinMode(rstbtn, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
static long lastCounter = 0;
long currentCounter = rotary.read() >> 2;
if (lastCounter != currentCounter) {
Serial.print("currentCounter: ");
Serial.println(currentCounter);
lastCounter = currentCounter;
}
if (digitalRead(rstbtn) == LOW) {
rotary.write(0);
lastCounter = 0;
Serial.println(0);
}
}