Bird
0
0
Arduinoprogramming~10 mins

Seven-segment display control in Arduino - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Seven-segment display control
Start
Initialize pins
Set digit to display
Turn on segments
Wait briefly
Repeat or change digit
End or loop
The program starts by setting up pins, then lights the correct segments to show a digit, waits, and repeats.
Execution Sample
Arduino
const int a = 2;
const int b = 3;
const int c = 4;
void setup() {
  pinMode(a, OUTPUT);
  pinMode(b, OUTPUT);
  pinMode(c, OUTPUT);
}
void loop() {
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, LOW);
  delay(1000);
}
This code turns on segments a and b, turns off c, showing part of a digit for 1 second repeatedly.
Execution Table
StepActionPin aPin bPin cOutput (Segments On)
1Setup pins as OUTPUTN/AN/AN/ANo segments lit yet
2Turn on segment aHIGHLOWLOWSegment a ON
3Turn on segment bHIGHHIGHLOWSegments a,b ON
4Turn off segment cHIGHHIGHLOWSegments a,b ON, c OFF
5Wait 1000 msHIGHHIGHLOWSegments a,b ON, c OFF
6Loop back to step 2HIGHHIGHLOWSegments a,b ON, c OFF
💡 Loop runs forever, continuously displaying segments a and b ON, c OFF
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4After Step 5Final
Pin aN/AHIGHHIGHHIGHHIGHHIGH
Pin bN/ALOWHIGHHIGHHIGHHIGH
Pin cN/ALOWLOWLOWLOWLOW
Key Moments - 3 Insights
Why do we set pinMode for each pin before using digitalWrite?
Because pins must be set as OUTPUT to control the segments; otherwise, digitalWrite won't turn the LEDs on or off (see step 1 in execution_table).
Why does the loop keep turning the same segments on and off?
The loop repeats to keep the display showing the digit continuously; without looping, the display would turn off after setup (see steps 5 and 6).
What happens if we set a segment pin to LOW?
Setting a segment pin to LOW turns that segment off, so it won't light up (see step 4 where pin c is LOW).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 3, what is the state of pin b?
ALOW
BHIGH
CN/A
DUndefined
💡 Hint
Check the 'Pin b' column in execution_table row for step 3.
At which step does the program wait before repeating?
AStep 5
BStep 2
CStep 4
DStep 6
💡 Hint
Look for the 'Wait 1000 ms' action in execution_table.
If pin c was set to HIGH at step 4, what would change in the output?
ANo change in segments
BSegment a would turn OFF
CSegment c would turn ON
DAll segments would turn OFF
💡 Hint
Refer to the 'Output (Segments On)' column and pin c state in execution_table.
Concept Snapshot
Seven-segment display control in Arduino:
- Define pins for each segment
- Set pins as OUTPUT in setup()
- Use digitalWrite(pin, HIGH/LOW) to turn segments ON/OFF
- Use delay() to keep display visible
- Loop to continuously show digits
Full Transcript
This example shows how to control a seven-segment display using Arduino. First, pins connected to segments are set as outputs. Then, in the loop, specific pins are set HIGH or LOW to turn segments on or off, forming digits. The program waits briefly to keep the display visible, then repeats. The execution table traces each step, showing pin states and which segments light up. Key points include setting pin modes before writing and looping to maintain the display. The quiz checks understanding of pin states and timing.