LennartHennigs / ESPRotary

Arduino/ESP library to simplify reading rotary encoder data.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Set Position

jjarp opened this issue · comments

commented

Hello, first all, thanks a lot for this excellent work.

I have a suggestion, add a setPosition function in order to if you reach the minimum limit and you move again the encoder, can go the maximum value again, this is a good way to move between menus or other practical functions.

Hey,
thanks for the kind words.
There is a resetPosition() function that allows you to set a value.
Is that what you are asking for?
Cheers.

commented

Yes you are right, anyway when I tried to reset the position to for example the value 4 (min bounds was -1 and max bounds was 5, also my moves per click is 4), when I tried to get the position the position was 1, after review the cpp file, was necessary modify this line:

void ESPRotary::resetPosition(int p /* = 0 */) {

if (p > upper_bound) {
last_position = upper_bound * moves_per_click;
} else {
last_position = (lower_bound > p) ? lower_bound * moves_per_click : p;
}

position = last_position*moves_per_click;
direction = 0;
}

after multiply by moves_per_click finally i get the correct value.

may be is necessary do a correction about it.

Thanks again.

Hey,
thanks for pointing it out!
I will fix it and upload it in the next couple of days.
Cheers
l.