// 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
// Light up the number of LEDs equal to the current number of seconds
for (int i = 0; i < currentSeconds; i++) {
int registerIndex = i / 8;
int bitIndex = i % 8;
bitSet(ledStates[registerIndex], bitIndex);
}
// Turn off the remaining LEDs
for (int i = currentSeconds; i < numLEDs; i++) {
int registerIndex = i / 8;
int bitIndex = i % 8;
bitClear(ledStates[registerIndex], bitIndex);
}
// Update the shift registers with the new LED states
updateShiftRegisters();
// Wait for 1 second before updating the LEDs again
delay(100);
}
/**
* 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);
}