// Define pins for the segments of the display
const int segmentPins[] = {7, 8, 9, 10, 11, 12, 13}; // Pins 0 to 6
const int numDigits = 7; // Number of segments
// Define the segments needed for each number (0-9) on the display
const byte numSegments[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
};
void setup() {
// Initialize segment pins as outputs
for (int i = 0; i < numDigits; i++) {
pinMode(segmentPins[i], OUTPUT);
}
}
void loop() {
// Loop through each number and display it on the 7-segment display
for (int num = 0; num < 10; num++) {
displayNumber(num);
delay(1000); // Display each number for 1 second
}
}
// Function to display a single number on the 7-segment display
void displayNumber(int num) {
// Turn on/off each segment according to the pattern for the given number
for (int segment = 0; segment < numDigits; segment++) {
digitalWrite(segmentPins[segment], numSegments[num][segment]);
}
}