Open dunkfordyce opened 3 days ago
Hi,
Thank you for trying out the library.
If you prefer to have the step as signed, you can simply do something like:
int my_step = (int) Encoder.step;
The cast is not strictly needed, but it helps document the fact that a conversion is happening there (to be more precise, it's not really a conversion, just a re-interpretation of the same value).
Another thing that you can do, if you just want the "delta" (the difference from the last time you checked the steps) is something like this:
static uint last_step; int delta;
Encoder.update(); delta = Encoder.step - last_step; last_step = Encoder.step;
Every time this runs, "delta" will have the positive or negative number of steps the encoder moved since the last call.
Note that if you're reading a rotary encoder, you'll probably see it moving 4 steps for each "click" of the encoder, so you may need to divide by 4 to get the number of clicks.
Cheers,
Hi,
This library works really well. The issue I have is for a simple use case, where
step
would seem to be the value I want to use, its unsigned so going negative makes a massive leap. Couldstep
not be signed to make it easier to use? Or is there some better way to use the available variables?Thanks