#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
#define ENCORDER_CLK 2
#define ENCORDER_DT 3
#define ENCORDER_SW 4
int counter = 0;
void setup() {
lcd.init();
lcd.backlight();
pinMode(ENCORDER_CLK, INPUT);
pinMode(ENCORDER_DT, INPUT);
pinMode(ENCORDER_SW, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(ENCORDER_CLK), readEncorder, FALLING);
}
void readEncorder() {
int dtValue = digitalRead(ENCORDER_DT);
if (dtValue == HIGH){
counter++;
}
if (dtValue == LOW) {
counter--;
}
}
void loop(){
lcd.setCursor(0,0);
lcd.print("counter");
lcd.setCursor(0,1);
lcd.print(counter);
}