#include <SPI.h>
// Define pins for data, latch, and clock of the shift register
const int dataPin = 2; // DS
const int latchPin = 3; // ST_CP
const int clockPin = 4; // SH_CP
void setup() {
// Set pins as output
pinMode(dataPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop() {
// Define patterns for each digit (0-9)
byte patterns[10] = {
B11000000, // 0
B11111001, // 1
B10100100, // 2
B10110000, // 3
B10011001, // 4
B10010010, // 5
B10000010, // 6
B11111000, // 7
B10000000, // 8
B10010000 // 9
};
// Loop through each digit
for (int i = 0; i < 10; i++) {
// Shift out the pattern for the current digit
shiftOut(dataPin, clockPin, MSBFIRST, patterns[i]);
// Latch the data to the output pins
digitalWrite(latchPin, HIGH);
// Hold latch state for a short while to display the digit
delay(5);
// Turn off all segments
shiftOut(dataPin, clockPin, MSBFIRST, B00000000);
digitalWrite(latchPin, LOW);
// Wait before displaying the next digit
delay(1000);
}
}