#define ENCODER_CLK 2
#define ENCODER_DT 15
void setup() {
Serial.begin(115200);
pinMode(ENCODER_CLK, INPUT);
pinMode(ENCODER_DT, INPUT);
}
int lastClk = HIGH;
int cont = 0;
void loop() {
int newClk = digitalRead(ENCODER_CLK);
if (newClk != lastClk) {
// There was a change on the CLK pin
lastClk = newClk;
Serial.println(lastClk);
Serial.println(newClk);
int dtValue = digitalRead(ENCODER_DT);
Serial.println(dtValue);
if (newClk == LOW && dtValue == HIGH) {
Serial.println("Rotated clockwise ⏩");
cont = cont + 1;
Serial.println(cont);
}
if (newClk == LOW && dtValue == LOW) {
Serial.println("Rotated counterclockwise ⏪");
cont = cont - 1;
Serial.println(cont);
}
}
}