// Define segment pins
const int A = 15;
const int B = 2;
const int C = 4;
const int D = 16;
const int E = 17;
const int F = 5;
const int G = 18;
const int DP = 19;
// Define common cathode pins for each display
const int displays[] = {21, 22, 23, 32, 33, 25, 26, 27, 14, 12};
// Digit segment patterns for common cathode (1 = ON, 0 = OFF)
// Each array represents the pattern for the digits 0-9
const bool digits[10][7] = {
{1, 1, 1, 1, 1, 1, 0}, // 0
{0, 1, 1, 0, 0, 0, 0}, // 1
{1, 1, 0, 1, 1, 0, 1}, // 2
{1, 1, 1, 1, 0, 0, 1}, // 3
{0, 1, 1, 0, 0, 1, 1}, // 4
{1, 0, 1, 1, 0, 1, 1}, // 5
{1, 0, 1, 1, 1, 1, 1}, // 6
{1, 1, 1, 0, 0, 0, 0}, // 7
{1, 1, 1, 1, 1, 1, 1}, // 8
{1, 1, 1, 1, 0, 1, 1} // 9
};
// Array of segment pins in order (A, B, C, D, E, F, G)
const int segmentPins[] = {A, B, C, D, E, F, G};
void setup() {
// Set segment pins as outputs
for (int i = 0; i < 7; i++) {
pinMode(segmentPins[i], OUTPUT);
}
pinMode(DP, OUTPUT);
// Set display pins as outputs
for (int i = 0; i < 10; i++) {
pinMode(displays[i], OUTPUT);
digitalWrite(displays[i], HIGH); // Turn off all displays initially
}
}
void loop() {
// Display numbers 1 to 9, then 0 on the 10 displays
for (int i = 0; i < 10; i++) {
displayDigit(i + 1); // Display numbers 1 to 9, then wrap to 0
digitalWrite(displays[i], LOW); // Turn on the current display
delay(500); // Hold the number for half a second
digitalWrite(displays[i], HIGH); // Turn off the display
}
}
// Function to display a single digit on the segments
void displayDigit(int number) {
if (number == 10) number = 0; // Wrap to 0 after 9
// Set each segment according to the digit pattern
for (int i = 0; i < 7; i++) {
digitalWrite(segmentPins[i], digits[number][i] ? HIGH : LOW);
}
// Optional: Set decimal point off
digitalWrite(DP, LOW);
}