// Define LED pins for Row 1 and Row 2
const int ledRow1[] = {2, 3, 4, 5, 6, 7, 8};
const int ledRow2[] = {9, 10, 11, 12, 13, A0, A1};
// Define button pins
const int buttonRow1 = A2;
const int buttonRow2 = A3;
// Define toggle switch pins
const int toggleSwitch1 = A4;
const int toggleSwitch2 = A5;
const int toggleSwitch3 = A6;
// Variables to track the current LED position
int currentLedRow1 = 0;
int currentLedRow2 = 0;
void setup() {
// Initialize LED pins as outputs
for (int i = 0; i < 7; i++) {
pinMode(ledRow1[i], OUTPUT);
pinMode(ledRow2[i], OUTPUT);
}
// Initialize button pins as inputs with pullup resistors
pinMode(buttonRow1, INPUT_PULLUP);
pinMode(buttonRow2, INPUT_PULLUP);
// Initialize toggle switch pins as inputs
pinMode(toggleSwitch1, INPUT);
pinMode(toggleSwitch2, INPUT);
pinMode(toggleSwitch3, INPUT);
Serial.begin(9600);
// Initialize LEDs
updateLeds();
}
void loop() {
// Check button for Row 1
if (digitalRead(buttonRow1) == LOW) {
delay(200); // Debounce delay
currentLedRow1 = (currentLedRow1 + 1) % 7;
updateLeds();
while(digitalRead(buttonRow1) == LOW); // Wait for button release
}
// Check button for Row 2
if (digitalRead(buttonRow2) == LOW) {
delay(200); // Debounce delay
if (digitalRead(toggleSwitch1) == HIGH) {
// State 1: No movement
}
else if (digitalRead(toggleSwitch2) == HIGH) {
// State 2: Move by one LED
currentLedRow2 = (currentLedRow2 + 1) % 7;
}
else if (digitalRead(toggleSwitch3) == HIGH) {
// State 3: Move two LEDs ahead
currentLedRow2 = (currentLedRow2 + 2) % 7;
}
updateLeds();
while(digitalRead(buttonRow2) == LOW); // Wait for button release
}
}
void updateLeds() {
// Turn off all LEDs for both rows
for (int i = 0; i < 7; i++) {
digitalWrite(ledRow1[i], LOW);
digitalWrite(ledRow2[i], LOW);
}
// Turn on the current LED for each row
digitalWrite(ledRow1[currentLedRow1], HIGH);
digitalWrite(ledRow2[currentLedRow2], HIGH);
Serial.println(currentLedRow1);
}