// Pin mapping for 7-segment display (for common cathode)
const int segmentPins[] = {2, 3, 4, 5, 6, 7, 8}; // A, B, C, D, E, F, G
const int digitPins[] = {9, 10, 11}; // DIG1, DIG2, DIG3
// Segment patterns for digits 0-9
const byte digitPatterns[10] = {
B00111111, // 0
B00000110, // 1
B01011011, // 2
B01001111, // 3
B01100110, // 4
B01101101, // 5
B01111101, // 6
B00000111, // 7
B01111111, // 8
B01101111 // 9
};
void setup() {
// Set segment pins and digit pins as output
for (int i = 0; i < 7; i++) {
pinMode(segmentPins[i], OUTPUT);
}
for (int i = 0; i < 3; i++) {
pinMode(digitPins[i], OUTPUT);
}
// Turn off all digits initially
for (int i = 0; i < 3; i++) {
digitalWrite(digitPins[i], HIGH);
}
}
void loop() {
// Display specific numbers: 000, 111, 222, ..., 999
for (int count = 0; count < 10; count++) {
output(count); // Display each number in the sequence
delay(1000); // Wait for 1 second for each number to be visible
}
}
// Function to output the same digit across all 3 digits
void output(int number) {
// Set segments for the current number
for (int j = 0; j < 7; j++) {
digitalWrite(segmentPins[j], (digitPatterns[number] >> j) & 0x01);
}
// Turn on all digits to show the current number
for (int i = 0; i < 3; i++) {
digitalWrite(digitPins[i], LOW); // Turn on current digit
}
// Keep the digits display on for 1 second
delay(1000);
// Turn off all digits after displaying
for (int i = 0; i < 3; i++) {
digitalWrite(digitPins[i], HIGH); // Turn off current digit
}
}