// Pin assignments
const int ledCount = 7; // Total number of LEDs
const int ledPins[ledCount] = {2, 3, 4, 5, 6, 7, 8}; // LED pins
const int state1Pin = 9; // Pin for state 1
const int state2Pin = 10; // Pin for state 2
const int state3Pin = 11; // Pin for state 3
int currentLedIndex = 0; // To keep track of the current LED
void setup() {
// Initialize LED pins as outputs
for (int i = 0; i < ledCount; i++) {
pinMode(ledPins[i], OUTPUT);
digitalWrite(ledPins[i], LOW); // Turn off all LEDs
}
// Initialize state pins as inputs with pull-up resistors
pinMode(state1Pin, INPUT_PULLUP);
pinMode(state2Pin, INPUT_PULLUP);
pinMode(state3Pin, INPUT_PULLUP);
}
void loop() {
// Read the state of each button
bool state1 = digitalRead(state1Pin) == LOW; // Active LOW
bool state2 = digitalRead(state2Pin) == LOW; // Active LOW
bool state3 = digitalRead(state3Pin) == LOW; // Active LOW
// Turn off the current LED
digitalWrite(ledPins[currentLedIndex], LOW);
// Determine the next LED index based on the states
if (state2) {
currentLedIndex = (currentLedIndex + 1) % ledCount; // move to the next LED
} else if (state3) {
currentLedIndex = (currentLedIndex + 2) % ledCount; // move 2 positions ahead
}
// if state 1 is true (but no action taken), we simply do nothing
// Turn on the current LED
digitalWrite(ledPins[currentLedIndex], HIGH);
// Optional: Wait for a short period to see the change
delay(300); // Adjust the delay as necessary
}