int ledPin = 8; //PB2 pin is the number 8
int buttonPin = 7; //Why number 7? Because my button is linked to the PA7
int buttonState; //buttonState
void setup() {
pinMode(ledPin, OUTPUT); //My led will remain an OUTPUT
pinMode(buttonPin, INPUT); //The button will be the INPUT
digitalWrite(buttonPin, HIGH); //activate button internal R-pull
}
void loop() { //start infinite loop
digitalWrite(ledPin, LOW); //This time I want the led switched off at the beginning
buttonState = digitalRead(buttonPin);
if(buttonState == LOW){ //I added an IF condition, because if button is pressed my led will switched on
digitalWrite(ledPin, HIGH); //LED is switched on
}
else{
digitalWrite(ledPin, LOW); //otherwise the led is switched off
}
}