Here is a example using polling with debounced digital read of the pins. It is designed to read every quadrature change. If your encoder has detents at every change, it will work. If the detents are not at every change, the code can be modified to increment/decrement only in the detent positions. The encoder you referenced has different options for the detents.
//Based on code from: http://bildr.org/2012/08/rotary-encoder-arduino/
//uses quadrature bit pattern from current and previous reading
//Changes
//Polled rather than interrupts
//Added start up position check to make index +1/-1 from first move
//Add bounce2 and debounce of digitalReads
#define encoderPinA 3
#define encoderPinB 2
#define buttonPin 5
#include <Bounce2.h>
// Instantiate three Bounce objects for all pins with digitalRead
Bounce debouncerA = Bounce();
Bounce debouncerB = Bounce();
Bounce debouncer5 = Bounce();
int lastEncoded = 0;
int encoderValue = 0;
int lastencoderValue = 0;
void setup() {
Serial.begin (115200);
pinMode(encoderPinA, INPUT_PULLUP);
pinMode(encoderPinB, INPUT_PULLUP);
pinMode(buttonPin, INPUT_PULLUP);
debouncerA.attach(encoderPinA);
debouncerA.interval(5);
debouncerB.attach(encoderPinB);
debouncerB.interval(5);
debouncer5.attach(buttonPin);
debouncer5.interval(5);
//get starting position
debouncerA.update();
debouncerB.update();
int lastMSB = debouncerA.read();
int lastLSB = debouncerB.read();
Serial.print("Starting Position AB " );
Serial.print(lastMSB);
Serial.println(lastLSB);
//let start be lastEncoded so will index on first click
lastEncoded = (lastMSB << 1) |lastLSB;
}
void loop(){
debouncerA.update();
debouncerB.update();
int MSB = debouncerA.read();//MSB = most significant bit
int LSB = debouncerB.read();//LSB = least significant bit
int encoded = (MSB << 1) |LSB; //converting the 2 pin values to single number
int sum = (lastEncoded << 2) | encoded; //adding it to the previous encoded value
//test against quadrature patterns CW and CCW
if(sum == 0b1101 || sum == 0b0100 || sum == 0b0010 || sum == 0b1011) encoderValue ++;
if(sum == 0b1110 || sum == 0b0111 || sum == 0b0001 || sum == 0b1000) encoderValue --;
lastEncoded = encoded; //store this value for next time
if(encoderValue != lastencoderValue){
Serial.print("Index: ");
Serial.print(encoderValue);
Serial.print('\t');
Serial.print("Old-New AB Pattern: ");
for (int i = 3; i >= 0; i-- )
{
Serial.print((sum >> i) & 0X01);//shift and select first bit
}
Serial.println();
lastencoderValue=encoderValue;
}
//reset index
debouncer5.update();
if(debouncer5.read()==LOW){
encoderValue=0;
}
}