// Define the pins connected to the 74HC595 ICs
#define DATA_PIN 2 // Connect to DS (serial data input) pin of 74HC595
#define CLOCK_PIN 3 // Connect to SHCP (shift register clock input) pin of 74HC595
#define LATCH_PIN 4 // Connect to STCP (storage register clock input) pin of 74HC595
void setup() {
// Set the 74HC595 control pins as outputs
pinMode(DATA_PIN, OUTPUT);
pinMode(CLOCK_PIN, OUTPUT);
pinMode(LATCH_PIN, OUTPUT);
}
void loop() {
// Define the LED matrix pattern (8x8 matrix)
byte matrixPattern[] = {
B10000000,
B01000000,
B00100000,
B00010000,
B00001000,
B00000100,
B00000010,
B00000001
};
// Loop through the LED matrix pattern
for (int i = 0; i < 8; i++) {
updateShiftRegisters(matrixPattern[i]);
delay(500); // Delay for demonstration purposes
}
}
// Function to update the shift registers with the desired LED matrix pattern
void updateShiftRegisters(byte rowData) {
// Loop through both shift registers
for (int shiftRegisterIndex = 0; shiftRegisterIndex < 2; shiftRegisterIndex++) {
// Calculate the data to be sent to the shift register
byte dataToSend = (rowData << shiftRegisterIndex);
// Send the data to the shift register
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, dataToSend);
}
// Latch the data into the storage register for both shift registers
digitalWrite(LATCH_PIN, HIGH);
digitalWrite(LATCH_PIN, LOW);
}