ok I agree, forgot to copy it
here the ISR
// Encoders
// *******************************************************************************************************************************
#define encoderRightA 29
#define encoderRightB 28
#define encoderLeftA 27
#define encoderLeftB 26
#define LT_PHASE_A digitalRead(encoderLeftA)
#define LT_PHASE_B digitalRead(encoderLeftB)
#define RT_PHASE_A digitalRead(encoderRightA)
#define RT_PHASE_B digitalRead(encoderRightB)
static volatile int16_t encDeltaLt, encDeltaRt;
static int16_t lastLt = 0, lastRt = 0;
int encLt = 0, encRt = 0;
ISR( TIMER2_COMPA_vect )
{
int16_t val, diff;
val = 0;
if ( LT_PHASE_A )
val = 3;
if ( LT_PHASE_B )
val ^= 1; // convert gray to binary
diff = lastLt - val; // difference last - new
if ( diff & 1 ) { // bit 0 = value (1)
lastLt = val; // store new as next last
encDeltaLt += (diff & 2) - 1; // bit 1 = direction (+/-)
}
val = 0;
if ( RT_PHASE_A )
val = 3;
if ( RT_PHASE_B )
val ^= 1; // convert gray to binary
diff = lastRt - val; // difference last - new
if ( diff & 1 ) { // bit 0 = value (1)
lastRt = val; // store new as next last
encDeltaRt += (diff & 2) - 1; // bit 1 = direction (+/-)
}
return;
}