// Define which Arduino pins are connected to the LED pins
int ledPins[] = {A0, A1, A2, A3, A4}; // Pins connected to the LEDs through resistors
int numLeds = 5; // Number of LEDs
//int runCount = 0; // Counter for the number of completed runs
//int maxRuns = 10; // Maximum number of runs
void setup() {
// Initialize all the LED pins as output
for (int i = 0; i < numLeds; i++) {
pinMode(ledPins[i], OUTPUT);
}
}
void loop() {
// Check if the maximum number of runs has been reached
// if (runCount >= maxRuns) {
// return; // Exit the loop function, ending the simulation
// }
// Forward direction: Light up each LED one by one
for (int i = 0; i < numLeds; i++) {
analogWrite(ledPins[i], 255); // Turn on the LED
delay(200); // Keep the LED on for 200 milliseconds
analogWrite(ledPins[i], 0); // Turn off the LED
}
// Reverse direction: Light up each LED one by one, except the first and last
for (int i = numLeds - 2; i > 0; i--) {
analogWrite(ledPins[i], 255); // Turn on the LED
delay(200); // Keep the LED on for 200 milliseconds
analogWrite(ledPins[i], 0); // Turn off the LED
}
// Increment the run count after each full sequence
// runCount++;
}