Bird
0
0
Arduinoprogramming~30 mins

Seven-segment display control in Arduino - Mini Project: Build & Apply

Choose your learning style9 modes available
Seven-segment display control
📖 Scenario: You have a seven-segment display connected to an Arduino board. Each segment is connected to a specific digital pin. You want to control the display to show numbers from 0 to 9 by turning on and off the correct segments.
🎯 Goal: Build a program that controls a seven-segment display by turning on the correct segments to show digits 0 through 9.
📋 What You'll Learn
Create an array called segmentPins with the exact digital pins connected to segments a to g: 2, 3, 4, 5, 6, 7, 8
Create a two-dimensional array called digits that holds the on/off pattern for each digit 0 to 9 for the seven segments
Write a function called displayDigit that takes a digit and lights up the correct segments
Use setup() to set all segment pins as outputs
Use loop() to display digits 0 to 9 with a 1-second delay between each
💡 Why This Matters
🌍 Real World
Seven-segment displays are common in clocks, counters, and simple numeric displays in appliances.
💼 Career
Understanding how to control hardware components like displays is essential for embedded systems and electronics programming jobs.
Progress0 / 4 steps
1
Set up segment pins array
Create an integer array called segmentPins with these exact values: 2, 3, 4, 5, 6, 7, 8 representing the Arduino pins connected to segments a to g.
Arduino
Hint

Use an integer array with the exact pin numbers in curly braces.

2
Create digit patterns array
Create a two-dimensional integer array called digits with 10 rows and 7 columns. Each row represents a digit 0 to 9. Each column is 1 or 0 to turn a segment on or off. Use this exact pattern:
{1,1,1,1,1,1,0}, {0,1,1,0,0,0,0}, {1,1,0,1,1,0,1}, {1,1,1,1,0,0,1}, {0,1,1,0,0,1,1}, {1,0,1,1,0,1,1}, {1,0,1,1,1,1,1}, {1,1,1,0,0,0,0}, {1,1,1,1,1,1,1}, {1,1,1,1,0,1,1}
Arduino
Hint

Use a 2D array with 10 rows and 7 columns exactly as shown.

3
Write displayDigit function
Write a function called displayDigit that takes an integer digit. Use a for loop with variable i from 0 to 6 to set each segment pin HIGH if digits[digit][i] is 1, else LOW. Use digitalWrite(segmentPins[i], HIGH) or digitalWrite(segmentPins[i], LOW) accordingly.
Arduino
Hint

Use a for loop from 0 to 6 and digitalWrite to control each segment.

4
Complete setup and loop to show digits
Write the setup() function to set all pins in segmentPins as OUTPUT using a for loop with variable i. Then write the loop() function to display digits 0 to 9 in order using a for loop with variable digit. Call displayDigit(digit) inside the loop and add delay(1000) to wait 1 second between digits.
Arduino
Hint

Use loops in setup() and loop() to set pins and show digits with delay.