// Define the GPIO pins for the 7-segment display
const int segmentPins[7] = { 35, 32, 33, 25, 26, 27, 14 }; // Define your GPIO connections
const int commonAnodePin = 5; // Common anode pin
// Common-Anode 7-segment display digit patterns
const byte numbers[10][7] = {
{0, 0, 0, 0, 0, 0, 1}, // 0
{1, 0, 0, 1, 1, 1, 1}, // 1
{0, 0, 1, 0, 0, 1, 0}, // 2
{0, 0, 0, 0, 1, 1, 0}, // 3
{1, 0, 0, 1, 1, 0, 0}, // 4
{0, 1, 0, 0, 1, 0, 0}, // 5
{0, 1, 0, 0, 0, 0, 0}, // 6
{0, 0, 0, 1, 1, 1, 1}, // 7
{0, 0, 0, 0, 0, 0, 0}, // 8
{0, 0, 0, 0, 1, 0, 0} // 9
};
void setup() {
// Set segment pins as OUTPUT
for (int i = 0; i < 7; i++) {
pinMode(segmentPins[i], OUTPUT);
}
pinMode(commonAnodePin, OUTPUT);
digitalWrite(commonAnodePin, HIGH); // Enable the common anode
}
void displayDigit(int digit) {
if (digit < 0 || digit > 9) return; // Invalid input handling
for (int i = 0; i < 7; i++) {
digitalWrite(segmentPins[i], numbers[digit][i]);
}
}
void loop() {
for (int i = 0; i < 10; i++) {
displayDigit(i);
delay(1000); // Display each digit for 1 second
}
}