add SW encoder callback support and example

This commit is contained in:
hathach committed 2017-09-14 23:54:08 +07:00
1 parent 5d03ea59d0
commit 3db9b9150a
3 files changed
+24 -9

No files matched your search

@@ -86,6 +86,11 @@ bool SwRotaryEncoder::begin(uint8_t pina, uint8_t pinb)
return true;
}
void SwRotaryEncoder::setCallback(callback_t fp)
{
_cb = fp;
}
void SwRotaryEncoder::stop(void)
{
detachInterrupt(_pina);
@@ -122,9 +127,11 @@ void SwRotaryEncoder::_irq_handler(void)
if ( val != digitalRead(_pinb) )
{
_abs++;
if (_cb) _cb(1);
}else
{
_abs--;
if (_cb) _cb(-1);
}
_a_last = val;