// https://forum.arduino.cc/t/arduino-debounce-button-logic-controlling-servos/1154479/10
const int buttonPin = 9;
int buttonState;
void loop () {
int but = digitalRead (buttonPin);
if (buttonState != but) {
buttonState = but;
delay (20); // debounce
if (LOW == but)
Serial.println ("pressed");
else
Serial.println ("released");
}
}
void setup () {
Serial.begin (9600);
pinMode (buttonPin, INPUT_PULLUP);
buttonState = digitalRead (buttonState);
}