If I call getDirection() I dont get the expected results.
CLOCKWISE is detected when I turn COUNTERCLOCKWISE.
The serial output below shows correct newPos is 0,1,2,3,4,3,2,1,0,-1,-2,-3,-4
But the corresponding ::Direction is not correct in every case.
It only is correct if newPos reaches 0.
I have no clue why - maybe because _positionExtPrev is not manipulated in tick().
Sketch
void loop()
{
static int pos = 0;
encoder.tick();
int newPos = encoder.getPosition();
if (pos != newPos) {
Serial.print(newPos);
Serial.println();
processEncoder(encoder);
pos = newPos;
} // if
// The End
void processEncoder(RotaryEncoder myEncoder)
{
switch (myEncoder.getDirection())
{
case RotaryEncoder::Direction::NOROTATION:
break;
case RotaryEncoder::Direction::CLOCKWISE:
{
Serial.println(F("CLOCKWISE"));
}
break;
case RotaryEncoder::Direction::COUNTERCLOCKWISE:
{
Serial.println(F("COUNTERCLOCKWISE"));
}
break;
default:
{
}
If I call getDirection() I dont get the expected results. CLOCKWISE is detected when I turn COUNTERCLOCKWISE.
The serial output below shows correct newPos is 0,1,2,3,4,3,2,1,0,-1,-2,-3,-4 But the corresponding ::Direction is not correct in every case. It only is correct if newPos reaches 0.
I have no clue why - maybe because _positionExtPrev is not manipulated in tick().
Sketch
void loop() { static int pos = 0; encoder.tick();
int newPos = encoder.getPosition(); if (pos != newPos) { Serial.print(newPos); Serial.println(); processEncoder(encoder); pos = newPos; } // if
// The End void processEncoder(RotaryEncoder myEncoder) { switch (myEncoder.getDirection()) { case RotaryEncoder::Direction::NOROTATION: break;
} }
} // loop ()
Serial output
COUNTERCLOCKWISE 0 1 CLOCKWISE 2 CLOCKWISE 3 CLOCKWISE 4 CLOCKWISE 3 CLOCKWISE 2 CLOCKWISE 1 CLOCKWISE 0 -1 COUNTERCLOCKWISE -2 COUNTERCLOCKWISE -3 COUNTERCLOCKWISE -4 COUNTERCLOCKWISE 2 CLOCKWISE 3 CLOCKWISE 4 CLOCKWISE 3 CLOCKWISE 2 CLOCKWISE 1 CLOCKWISE 0 -1 COUNTERCLOCKWISE -2 COUNTERCLOCKWISE -3 COUNTERCLOCKWISE -4 COUNTERCLOCKWISE