const int ledpin=13;
const int button=2;
int switchState = 0; // variable to store the switch status
void setup() {
// put your setup code here, to run once:
pinMode(ledpin, OUTPUT);
pinMode(button, INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
switchState = digitalRead(button); // Read the state of the switch
if (switchState == HIGH)
{
digitalWrite(ledpin, HIGH); // Turn on the LED
Serial.println("LED ON"); // Print message to serial monitor
}
else
{
digitalWrite(ledpin, LOW); // Turn off the LED
Serial.println("LED OFF"); // Print message to serial monitor
}
delay(1000);
}