bombatuino/source/libraries/bombatuino_ROTARY_ENCODER/bombatuino_ROTARY_ENCODER.cpp

33 lines
610 B
C++
Raw Permalink Normal View History

2013-03-12 14:53:27 +01:00
#include "Arduino.h"
#include "bombatuino_ROTARY_ENCODER.h"
ROTARY_ENCODER::ROTARY_ENCODER(XcrementFunction incrementFunction, XcrementFunction decrementFunction) {
_increment = incrementFunction;
_decrement = decrementFunction;
_pinA = LOW;
_pinB = LOW;
2013-05-14 22:03:11 +02:00
_oldA = LOW;
2013-03-12 14:53:27 +01:00
}
2013-05-14 22:03:11 +02:00
void ROTARY_ENCODER::setPinA(int value) {
_pinA = value;
2013-03-12 14:53:27 +01:00
onPinChange();
}
2013-05-14 22:03:11 +02:00
void ROTARY_ENCODER::setPinB(int value) {
_pinB = value;
2013-03-12 14:53:27 +01:00
onPinChange();
}
void ROTARY_ENCODER::onPinChange() {
if ((_oldA == LOW) && (_pinA == HIGH)) {
if (_pinB == LOW) {
(*_increment)();
}
else {
(*_decrement)();
}
}
_oldA = _pinA;
}