1234567891011121314151617181920212223242526272829303132333435 |
- #include <Arduino.h>
-
- #include "config.h"
- #include "debounce.h"
-
- Debouncer::Debouncer(int p) : pin(p), currentState(0), lastState(0), lastTime(0) { }
-
- int Debouncer::poll() {
- int ret = 0;
- int state = digitalRead(pin);
-
- if (state != lastState) {
- lastTime = millis();
- }
-
- if ((millis() - lastTime) > DEBOUNCE_DELAY) {
- if (state != currentState) {
- currentState = state;
- if (currentState == LOW) {
- ret = 1;
- }
-
- /*
- Serial.print("Debounce: ");
- Serial.print(pin);
- Serial.print(" = ");
- Serial.println(state);
- */
- }
- }
-
- lastState = state;
- return ret;
- }
|