const int BTN_PD_PIN = 9;
const int BTN_PU_PIN = 8;
int oldPDVal = LOW;
int oldPUVal = HIGH;
void setup() {
Serial.begin(115200);
pinMode(BTN_PD_PIN, INPUT);
pinMode(BTN_PU_PIN, INPUT_PULLUP);
}
void loop() {
int pdValue = digitalRead(BTN_PD_PIN);
if (pdValue != oldPDVal) {
oldPDVal = pdValue;
if (pdValue == HIGH) {
Serial.println("Pull down pressed.");
}
delay(20);
}
int puValue = digitalRead(BTN_PU_PIN);
if (puValue != oldPUVal) {
oldPUVal = puValue;
if (puValue == LOW) {
Serial.println("Pull up pressed.");
}
delay(20);
}
}
Pull down
Pull up