bool recent_status; bool current_status; void setup() { // put your setup code here, to run once: pinMode(16, INPUT_PULLUP); pinMode(18, OUTPUT); Serial.begin(9600); } void loop() { current_status = digitalRead(16); if (current_status == LOW && recent_status == HIGH) { recent_status = LOW; Serial.println("1"); delay(10); } if (current_status == HIGH && recent_status == LOW) { recent_status = HIGH; Serial.println("2"); delay(10); } }