sources and files for the bombatuino project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
612 B

  1. #include "Arduino.h"
  2. #include "bombatuino_ROTARY_ENCODER.h"
  3. ROTARY_ENCODER::ROTARY_ENCODER(XcrementFunction incrementFunction, XcrementFunction decrementFunction) {
  4. _increment = incrementFunction;
  5. _decrement = decrementFunction;
  6. _pinA = LOW;
  7. _pinB = LOW;
  8. _oldA = LOW;
  9. }
  10. void ROTARY_ENCODER::setPinB(int value) {
  11. _pinB = value;
  12. onPinChange();
  13. }
  14. void ROTARY_ENCODER::setPinA(int value) {
  15. _pinA = value;
  16. onPinChange();
  17. }
  18. void ROTARY_ENCODER::onPinChange() {
  19. if ((_oldA == LOW) && (_pinA == HIGH)) {
  20. if (_pinB == LOW) {
  21. (*_increment)();
  22. }
  23. else {
  24. (*_decrement)();
  25. }
  26. }
  27. _oldA = _pinA;
  28. }