const int LED_PIN = 4;
const int BTN_PIN = 5;
void setup() {
Serial.begin(115200);
pinMode( LED_PIN, OUTPUT );
// Use the internal pullup resistor on GPIO pin.
pinMode( BTN_PIN, INPUT_PULLUP );
}
int saved_value = HIGH; // Used to save the last changed value.
void loop() {
// Read the input value from the button pin.
int value = digitalRead( BTN_PIN );
if ( saved_value != value ) {
// Show the input value.
Serial.printf( "Input value changed: %d\n", value );
// Save the new input value.
saved_value = value;
}
// Write the inverted input value to the output LED pin.
digitalWrite( LED_PIN, !value );
delay(10);
}