#define BUTTON_PIN 14 // data line for the feature button
byte buttonState = LOW;
unsigned long timePreviousButtonChange = millis();
unsigned long debounceDelay = 0;
void setup() {
Serial.begin(115200);
pinMode(BUTTON_PIN, INPUT);
}
void loop() {
unsigned long timeNow = millis();
if ((timeNow - timePreviousButtonChange) > debounceDelay) {
// this code is only reached if bounceDelay interval since last change has passed
byte newButtonState = digitalRead(BUTTON_PIN); // read the button state
// button state has changed
if (newButtonState != buttonState) {
buttonState = newButtonState; // update state variable
timePreviousButtonChange = timeNow;//update time of last button state change
if (buttonState == HIGH) {
Serial.println("button pressed");
} else {
Serial.println("button released");
}
}
}
}