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.

32 lines
429 B

5 years ago
  1. #include <Arduino.h>
  2. #include <Wire.h>
  3. #include "Button.h"
  4. Button::Button(uint8_t _pin, uint8_t _mode)
  5. {
  6. pin = _pin;
  7. mode = _mode;
  8. }
  9. void Button::begin()
  10. {
  11. if (mode == LOW)
  12. {
  13. pinMode(pin, INPUT_PULLUP);
  14. }
  15. else if (mode == HIGH)
  16. {
  17. pinMode(pin, INPUT);
  18. }
  19. }
  20. void Button::loop(ButtonCallbackFunction callback)
  21. {
  22. if (digitalRead(pin) == mode)
  23. {
  24. (*callback)();
  25. // debounce
  26. delay(250);
  27. }
  28. }