// Pin definitions for 74HC595
const int dataPin = 11; // DS
const int latchPin = 8; // ST_CP
const int clockPin = 12; // SH_CP
void setup() {
// Set pins as output
pinMode(dataPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop() {
// Loop through each LED from left to right
for (int i = 0; i < 8; i++) {
byte ledState = 1 << i; // Shift 1 bit to the left
updateShiftRegister(ledState);
delay(200);
}
// Loop through each LED from right to left
for (int i = 6; i >= 0; i--) {
byte ledState = 1 << i;
updateShiftRegister(ledState);
delay(200);
}
}
void updateShiftRegister(byte data) {
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data); // Send the byte
digitalWrite(latchPin, HIGH); // Latch it to output
}