mathertel / RotaryEncoder

RotaryEncoder Arduino Library
Other
328 stars 107 forks source link

reversing rotation direction skips one count #28

Closed mkrzewic closed 3 years ago

mkrzewic commented 3 years ago

in version 1.5.0 when reversing the direction of the knob the first getDirection returns 0 (norotation), needs one more tick to start reporting the proper direction. With 1.3.0 it works correctly.

mathertel commented 3 years ago

I will check... What encode do you use (init parameters)

mkrzewic commented 3 years ago

just the simplest default: RotaryEncoder encoder(encoderPin1, encoderPin2); (but i did try the non-default latching modes in 1.5.0, all have the same problem.)

i'm using interrupts to read, and get the direction like this:

auto dir = static_cast(encoder.getDirection());

bluesky81 commented 3 years ago

Hello, same problem in my project... What is different from 1.3.0 to 1.5.0? Should I use 1.3.0?

mathertel commented 3 years ago

I cannot easily reproduce. Please check that the inputs are both HIGH in the case of staying in a latch position. See src\RotaryEncoder.cpp # 33.

If this is not the case then use another mode like LatchMode::FOUR0

In case this is not successful, please let me know how the input changes when slowly turning the knob.

// positions: [3] 1 0 2 [3] 1 0 2 [3] // [3] is the positions where this rotary switch stops. It has 4 states until it stops again. // mode = FOUR3 // ==> right, count up // <== left, count down

Phantasmagory commented 3 years ago

Hello. I tried to do something like this: if (enc.isLeft()) i--; if (enc.isRight()) i++; and get this: Screenshot 2021-04-27 225659 maybe I'm not using the function correctly?

Llaves commented 3 years ago

I encountered the same issue with LatchMode::Four0 (the default). After examining the state sequence I determined my encoder latched on 3, not 0. Changing to LatchMode::Four3 made the problem disappear.

mathertel commented 3 years ago

Thanks for the hint.