int buttonPin = 2; // Input pin for the button
int ledPin = 13; // Output pin for the LED
void setup() {
pinMode(buttonPin, INPUT); // Set button pin as input
pinMode(ledPin, OUTPUT); // Set LED pin as output
}
void loop() {
int buttonState = digitalRead(buttonPin); // Read the button state
while (buttonState == LOW) {
// Blink the LED while the button is NOT pressed
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
buttonState = digitalRead(buttonPin); // Recheck the button state in each loop iteration
}
}