#include <SevSegShift.h>
#define SHIFT_PIN_SHCP 11
#define SHIFT_PIN_STCP 10
#define SHIFT_PIN_DS 9
SevSegShift sevseg(SHIFT_PIN_DS, SHIFT_PIN_SHCP, SHIFT_PIN_STCP, 1, true);
unsigned long lastUpdate = 0; // To track the time since the last update
int currentPattern = 0; // Index to track which pattern to show
const int patternDelay = 50; // Time (in milliseconds) between pattern changes
// Define your custom patterns for each digit (4 digits, 8 segments per digit)
byte patterns[60][4] = {
// Pattern #1: Custom segment combinations for each digit
{0b00000001, 0b00000000, 0b00000000, 0b00000000},
{0b00000001, 0b00000001, 0b00000000, 0b00000000},
{0b00000001, 0b00000001, 0b00000001, 0b00000000},
{0b00000001, 0b00000001, 0b00000001, 0b00000001},
{0b00000001, 0b00000001, 0b00000001, 0b00000011}, //5
{0b00000001, 0b00000001, 0b00000001, 0b00000111},
{0b00000001, 0b00000001, 0b00000001, 0b00001111},
{0b00000001, 0b00000001, 0b00001001, 0b00001111},
{0b00000000, 0b00001001, 0b00001001, 0b00001111},
{0b00001000, 0b00001000, 0b00001001, 0b00001111}, //10
{0b00011000, 0b00001000, 0b00001000, 0b00001111},
{0b00111000, 0b00001000, 0b00001000, 0b00001110},
{0b00111001, 0b00001000, 0b00001000, 0b00001100},
{0b00111001, 0b00001001, 0b00001000, 0b00001000},
{0b00111001, 0b00001001, 0b00001001, 0b00000000}, //15
{0b00111001, 0b00001001, 0b00000001, 0b00000000},
{0b00111001, 0b00000001, 0b00000011, 0b00000000},
{0b00110001, 0b00000001, 0b01000011, 0b00000000},
{0b00100001, 0b00000001, 0b01010011, 0b00000000},
{0b00000001, 0b00000001, 0b01011011, 0b00000000},
{0b00000000, 0b00000001, 0b01011011, 0b00000000},
{0b00000000, 0b00000000, 0b01011011, 0b00000000},
{0b00000000, 0b00000000, 0b01011011, 0b00000000},
{0b00000000, 0b00000000, 0b01011011, 0b00000000},
{0b00000000, 0b00000000, 0b01011011, 0b00000000},
{0b00000000, 0b00000000, 0b01011011, 0b00000000},
{0b00000000, 0b00000000, 0b01011011, 0b00000000},
{0b00000000, 0b00000000, 0b01011011, 0b00000000},
{0b00001001, 0b00001001, 0b01011011, 0b00001001},
{0b00001001, 0b00001001, 0b01011011, 0b00001001},
{0b00001001, 0b00001001, 0b01011011, 0b00001001},
{0b00000000, 0b00000000, 0b01011011, 0b00000000},
{0b00000000, 0b00000000, 0b01011011, 0b00000000},
{0b00000000, 0b00000000, 0b01011011, 0b00000000},
{0b00001001, 0b00001001, 0b01011011, 0b00001001},
{0b00001001, 0b00001001, 0b01011011, 0b00001001},
{0b00001001, 0b00001001, 0b01011011, 0b00001001},
{0b00000000, 0b00000000, 0b01011011, 0b00000000},
{0b00000000, 0b00000000, 0b01011011, 0b00000000},
{0b00000000, 0b00000000, 0b01011011, 0b00000000},
{0b00001001, 0b00001001, 0b01011011, 0b00001001},
{0b00001001, 0b00001001, 0b01011011, 0b00001001},
{0b00001001, 0b00001001, 0b01011011, 0b00001001},
{0b00000000, 0b00000000, 0b01011011, 0b00000000},
{0b00000000, 0b00000000, 0b01011011, 0b00000000},
{0b00000000, 0b00000000, 0b01011011, 0b00000000},
{0b00001001, 0b00001001, 0b01011011, 0b00001001},
{0b00001001, 0b00001001, 0b01011011, 0b00001001},
{0b00001001, 0b00001001, 0b01011011, 0b00001001},
{0b00000000, 0b00000000, 0b01011011, 0b00000000},
{0b00000000, 0b00000000, 0b00000000, 0b00000000},
{0b00000000, 0b00000000, 0b00000000, 0b00000000},
{0b00001001, 0b00001001, 0b01011011, 0b00001001},
{0b00001001, 0b00001001, 0b01011011, 0b00001001},
{0b00001001, 0b00001001, 0b01011011, 0b00001001},
{0b00000000, 0b00000000, 0b00000000, 0b00000000},
{0b00000000, 0b00000000, 0b00000000, 0b00000000},
{0b00000000, 0b00000000, 0b00000000, 0b00000000},
{0b00000000, 0b00000000, 0b00000000, 0b00000000},
{0b00000000, 0b00000000, 0b00000000, 0b00000000},
};
void setup() {
byte numDigits = 4;
byte digitPins[] = {A0, A1, A2, A3}; // Pins of the Arduino
byte segmentPins[] = {0, 1, 2, 3, 4, 5, 6, 7}; // Pins of the shift register
bool resistorsOnSegments = false;
byte hardwareConfig = COMMON_ANODE;
bool updateWithDelays = false;
bool leadingZeros = false;
bool disableDecPoint = false;
sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelays, leadingZeros, disableDecPoint);
sevseg.setBrightness(10);
}
void loop() {
unsigned long currentMillis = millis();
// Update the pattern every 'patternDelay' milliseconds
if (currentMillis - lastUpdate >= patternDelay) {
lastUpdate = currentMillis; // Reset the timer
// Display the current pattern
displayPattern(currentPattern);
// Move to the next pattern, loop back to the first pattern after the last one
currentPattern++;
if (currentPattern >= 60) {
currentPattern = 0;
}
}
// Refresh the display constantly
sevseg.refreshDisplay();
}
// Function to display a custom pattern on all 4 digits
void displayPattern(int patternIndex) {
byte segmentData[4]; // Array to hold segment data for all digits
// Loop through all 4 digits
for (int i = 0; i < 4; i++) {
// Set custom segments on each digit based on the current pattern
segmentData[i] = patterns[patternIndex][i];
}
// Set the segments for all digits at once
sevseg.setSegments(segmentData);
}