#include <LiquidCrystal>
LiquidCrystal_I2C LCD = LiquidCrystal_I2C(0x27, 16, 2);
#define outputA 4
#define outputB 5
int counter = 0;
int aState;
int aLastState;
void setup() {
pinMode (outputA,INPUT);
pinMode (outputB,INPUT);
Serial.begin (9600);
// Reads the initial state of the outputA
aLastState = digitalRead(outputA);
LCD.init();
// turn on LCD backlight
LCD.backlight();
}
void loop() {
aState = digitalRead(outputA); // Reads the "current" state of the outputA
// If the previous and the current state of the outputA are different, that means a Pulse has occured
if (aState != aLastState){
// If the outputB state is different to the outputA state, that means the encoder is rotating clockwise
if (digitalRead(outputB) != aState) {
counter++;
} else {
counter--;
}
Serial.print("Position:");
Serial.println(counter);
LCD.setCursor(0, 0);
// print message
LCD.print("Position:");
LCD.print(counter);
}
aLastState = aState; // Updates the previous state of the outputA with the current state
}
esp:0
esp:2
esp:4
esp:5
esp:12
esp:13
esp:14
esp:15
esp:16
esp:17
esp:18
esp:19
esp:21
esp:22
esp:23
esp:25
esp:26
esp:27
esp:32
esp:33
esp:34
esp:35
esp:3V3
esp:EN
esp:VP
esp:VN
esp:GND.1
esp:D2
esp:D3
esp:CMD
esp:5V
esp:GND.2
esp:TX
esp:RX
esp:GND.3
esp:D1
esp:D0
esp:CLK
encoder1:CLK
encoder1:DT
encoder1:SW
encoder1:VCC
encoder1:GND
lcd1:GND
lcd1:VCC
lcd1:SDA
lcd1:SCL