// Pin setup pour les 74HC595
const int dataPin = 2; // DS (Data)
const int clockPin = 3; // SH_CP (Shift Clock)
const int latchPin = 4; // ST_CP (Storage Clock)
// Define the number of LEDs and shift registers
const int numLEDs = 60;
const int numRegisters = 8;
// Array to store the LED states
byte ledStates[numRegisters];
void setup() {
// Set the shift register pins as outputs
pinMode(dataPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop() {
// Get the current number of seconds
int currentSeconds = millis() / 1000;
currentSeconds = currentSeconds % 60; // Reset to 0 after 60 seconds
// Reset all LEDs (turn them off)
for (int i = 0; i < numRegisters; i++) {
ledStates[i] = 0; // Clear all LEDs in the register
}
// Light up the LED corresponding to the current second
if (currentSeconds < numLEDs) {
int registerIndex = currentSeconds / 8;
int bitIndex = currentSeconds % 8;
bitSet(ledStates[registerIndex], bitIndex);
}
// Update the shift registers with the new LED states
updateShiftRegisters();
// Wait for 1 second before updating the LEDs again
delay(1000); // Wait for 1 second
}
/**
* Update the shift registers with the current LED states.
*/
void updateShiftRegisters() {
// Latch the data to the outputs of the shift registers
digitalWrite(latchPin, LOW);
// Shift out the LED states to the shift registers
for (int i = numRegisters - 1; i >= 0; i--) {
shiftOut(dataPin, clockPin, MSBFIRST, ledStates[i]);
}
// Latch the data to the outputs of the shift registers
digitalWrite(latchPin, HIGH);
}