const int buttonPin = 8;
const int ledPin = 20;
// State of the push button
int buttonState = 0;
void setup() {
Serial.begin(115200);
//Set the pin as an input pullup
pinMode(buttonPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
}
void loop() {
buttonState = digitalRead(buttonPin);
Serial.println(buttonState);
if (buttonState == LOW) {
// Switch on the led
digitalWrite(ledPin, HIGH);
} else {
// Switch off the led
digitalWrite(ledPin, LOW);
}
}