#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd (0x27, 16, 2);
#define ENCODER_CLK 2
#define ENCODER_DT 3
#define ENCODER_SW 4
int counter = 0;
void setup() {
lcd. init ();
lcd. backlight ();
delay(2000);
lcd.clear();
pinMode(ENCODER_CLK, INPUT);
pinMode(ENCODER_DT, INPUT);
// pinMode(ENCODER_SW, OUTPUT);
attachInterrupt(digitalPinToInterrupt(ENCODER_CLK), readEncoder, FALLING);
}
void readEncoder() {
// put your main code here, to run repeatedly:
int dtValue = digitalRead(ENCODER_DT);
if (dtValue == HIGH) {
counter++;
}
if (dtValue == LOW) {
counter--;
}
}
void loop() {
lcd.setCursor(0,0);
lcd.print("COUNTER: ");
lcd.print(counter);
delay(1);
// Do whatever
}