// Define pins for LEDs
int led1 = 2;
int led2 = 3;
// Set pins as output erore deve stare nel setup
//pinMode(led1, OUTPUT);
//pinMode(led2, OUTPUT);
// Create a variable to keep track of which LED is currently on
int currentLED = 1;
// Function to turn on LED1 and turn off LED2
void turnOnLED1() {
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
}
// Function to turn on LED2 and turn off LED1
void turnOnLED2() {
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
}
// Main code
void setup() {
// Set pins as output
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
}
void loop() {
// Check which LED is currently on and switch to the other one
if (currentLED == 1) {
turnOnLED2();
currentLED = 2;
} else {
turnOnLED1();
currentLED = 1;
}
// Delay for 1 second before switching again
delay(1000);
}
// Code sourced from: https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay