#define ENCODER_DO_NOT_USE_INTERRUPTS
#include <Encoder.h>
// Rotary Encoder Pins
#define ENCODER1_CLK 2
#define ENCODER1_DT 3
#define ENCODER2_CLK 4
#define ENCODER2_DT 5
#define BUTTON_PIN 6
Encoder Enc1(ENCODER1_CLK, ENCODER1_DT);
Encoder Enc2(ENCODER2_CLK, ENCODER2_DT);
long last1;
long last2;
long position1;
long position2;
void setup()
{
Serial.begin(115200);
Serial.println("Started");
pinMode(BUTTON_PIN, INPUT_PULLUP);
}
void loop()
{
bool update = false;
// Encoder 1
long new1 = Enc1.read() / -4;
if (new1 != last1)
{
update = true;
position1 = new1;
last1 = new1;
}
// Encoder 2
long new2 = Enc2.read() / -4;
if (new2 != last2)
{
update = true;
position2 = new2;
last2 = new2;
}
if(update)
{
Serial.print("Enc1 = ");
Serial.print(position1);
Serial.print(", Enc2 = ");
Serial.println(position2);
}
// Optional delay, it messes up the encoder!
// delay(10);
}
Encoder 1
Encoder 2