mathertel / RotaryEncoder

RotaryEncoder Arduino Library
Other
328 stars 107 forks source link

safer interrupt handling and funciton added for direction detection #7

Closed sysshad closed 6 years ago

sysshad commented 6 years ago

All variables changed by an interrupt should have the volatile keyword so the compiler wont think in some optimization mode that these variables never change. Also added an easy function to only check direction of movement instead that the user must read and check the actual value :)

sysshad commented 6 years ago

Np, thanks for making the library in the first place 👍 Saved me some work hehe.

I made another mod on how to handle the button press, if its down, up, tapped (with debounce check) or held down for x seconds. But its a bigger mod, and i think there are other nicer libraries out there to handle buttons :) mine is quite ugly and relies on using millis() and a polling function in the main loop instead of using interrupt and timer which is is a better way to do it, but is more work :D

Thanks again!

sysshad commented 6 years ago

Oh and btw.. i saw that getDirection function can be improved... lol silly me. put the _positionExtPrev = _positionExt; below the if blocks, its called everytime anyway lol, so no need for 3 declarations :P