//**********************************************************************************
/*
* Filename : Encoder
* Description : Rotary encoder module counting.
* Auther : http//www.keyestudio.com
*/
//Interfacing Rotary Encoder with Arduino
//Encoder Switch -> pin 27
//Encoder DT -> pin 14
//Encoder CLK -> pin 12
int ENCODER_DT = 14;
int ENCODER_CLK = 12;
int Encoder_Switch = 27;
void setup() {
Serial.begin(9600);
pinMode(ENCODER_CLK, INPUT);
pinMode(ENCODER_DT, INPUT);
attachInterrupt(digitalPinToInterrupt(ENCODER_CLK), readEncoder, FALLING);
}
void readEncoder() {
int dtValue = digitalRead(ENCODER_DT);
if (dtValue == HIGH) {
Serial.println("Rotated clockwise ⏩");
}
if (dtValue == LOW) {
Serial.println("Rotated counterclockwise ⏪");
}
}
void loop() {
// Do whatever
}