No Description
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.

debounce.cpp 721B

1234567891011121314151617181920212223242526272829303132333435
  1. #include <Arduino.h>
  2. #include "config.h"
  3. #include "debounce.h"
  4. Debouncer::Debouncer(int p) : pin(p), currentState(0), lastState(0), lastTime(0) { }
  5. int Debouncer::poll() {
  6. int ret = 0;
  7. int state = digitalRead(pin);
  8. if (state != lastState) {
  9. lastTime = millis();
  10. }
  11. if ((millis() - lastTime) > DEBOUNCE_DELAY) {
  12. if (state != currentState) {
  13. currentState = state;
  14. if (currentState == LOW) {
  15. ret = 1;
  16. }
  17. /*
  18. Serial.print("Debounce: ");
  19. Serial.print(pin);
  20. Serial.print(" = ");
  21. Serial.println(state);
  22. */
  23. }
  24. }
  25. lastState = state;
  26. return ret;
  27. }