// Define the row pins (anodes)
const int rowPins[4] = {2, 3, 4, 5}; // Rows connected to digital pins 2, 3, 4, 5
void setup() {
// Set row pins as outputs
for (int i = 0; i < 4; i++) {
pinMode(rowPins[i], OUTPUT);
digitalWrite(rowPins[i], LOW); // Initially set all rows to LOW
}
}
void loop() {
// Light up LEDs in a diagonal pattern (0,0), (1,1), (2,2), (3,3)
for (int row = 0; row < 4; row++) {
clearAll();
digitalWrite(rowPins[row], HIGH); // Set the current row HIGH
delay(500); // Wait for a short period
}
}
void clearAll() {
// Set all rows to LOW
for (int i = 0; i < 4; i++) {
digitalWrite(rowPins[i], LOW); // Turn off all rows
}
}