/*
MSJ Researchers World
Date - 21st OCT 2024
Mentor - Mr. Siranjeevi M
Contact - 7373771991
*/
// Pin assignments
const int ledPin = 4;
const int buttonPin = 6;
// Variable to store button state
int buttonState = 0;
void setup()
{
pinMode(ledPin, OUTPUT); // Set LED pin as output
pinMode(buttonPin, INPUT); // Set button pin as input
}
void loop() {
// Read the state of the button
buttonState = digitalRead(buttonPin);
// If button is pressed, blink the LED
if (buttonState == LOW)
{ // LOW means button pressed (with pull-up)
digitalWrite(ledPin, HIGH); // LED ON
delay(500); // Wait 500ms
digitalWrite(ledPin, LOW); // LED OFF
delay(500); // Wait 500ms
}
else
{
digitalWrite(ledPin, LOW); // Ensure LED stays OFF when button not pressed
}
}