// Pin definitions
int datapin = 2; // DS (data pin)
int clockpin = 3; // SHCP (shift clock pin)
int latchpin = 4; // STCP (latch pin)
// Create an array to hold the data for all 10 shift registers
byte shiftRegisterData[10] = {0};
void setup() {
pinMode(datapin, OUTPUT);
pinMode(clockpin, OUTPUT);
pinMode(latchpin, OUTPUT);
}
void loop() {
// Example: Turn on one LED at a time across all 80 outputs
for (int i = 0; i < 80; i++) {
clearShiftRegisters(); // Clear all outputs
setShiftRegister(i, HIGH); // Set the specific LED ON
updateShiftRegisters(); // Send data to the shift registers
delay(100); // Pause for visibility
}
}
// Clear all shift register outputs
void clearShiftRegisters() {
for (int i = 0; i < 10; i++) {
shiftRegisterData[i] = 0;
}
}
// Set a specific output HIGH or LOW
void setShiftRegister(int output, boolean state) {
int registerIndex = output / 8; // Determine which register (0-9)
int bitIndex = output % 8; // Determine which bit within the register (0-7)
bitWrite(shiftRegisterData[registerIndex], bitIndex, state);
}
// Update the shift registers with the current data
void updateShiftRegisters() {
digitalWrite(latchpin, LOW); // Prepare to send data
for (int i = 9; i >= 0; i--) { // Send data to all 10 registers
shiftOut(datapin, clockpin, MSBFIRST, shiftRegisterData[i]);
}
digitalWrite(latchpin, HIGH); // Latch to display the new data
}