wokwi-7segment Reference
Seven segment LED display
Pin names
Name | Description |
---|---|
A | Top segment |
B | Top-right segment |
C | Bottom-right segment |
D | Bottom segment |
E | Bottom-left segment |
F | Top-left segment |
G | Middle segment |
DP | Dot LED |
COM | Common pin* |
DIG1 | Digit 1 pin* |
DIG2 | Digit 2 pin* |
DIG3 | Digit 3 pin* |
DIG4 | Digit 4 pin* |
CLN | Colon pin (optional) |
* COM is the common pin for a single digit 7-segment display. For multi digit displays, use DIG1…DIG4.
With the default common
attribute setting of anode
, the segment pins (A…G, DP, CLN) are connected to the cathode (negative side) of the LEDS, and the common pins (COM, DIG1…DIG4) are connected to the anode (positive side) of the LEDs. Segments are lit by driving their pins low. Setting common
to cathode
reverses this behavior, with the segment pins turning on when high.
The segment mapping is as follows:
And the digit mapping:
Attributes
Name | Description | Default value |
---|---|---|
common | The common pin: "cathode" or "anode" | "anode" |
digits | Number of digits: "1", "2", "3" or "4" | "1" |
colon | Set to "1" to show the colon (clock mode) | "" |
color | The color of the segment LEDs | "red" |
Examples
Result | Attrs |
---|---|
{ "color": "green" } | |
{ "color": "#d040d0" } | |
{ "digits": "2" } | |
{ "digits": "4" } | |
{ "digits": "4", "colon": "1" } |
Using the 7-segment display
For a single digit, you'll need 8 microcontroller GPIO pins. Each pin should be connected to a single segment through a resistor, and the common pin should be connected to 5V (or GND if you are using the common cathode variant). You can spare one pin (DP) if you don't use the dot LED. Turn a segment on by driving the corresponding segment on (or HIGH for the common cathode variant).
For multiple digits, you'll need 8 microcontroller pins for the segments and the dot plus one extra microcontroller pin for each digit. So if you have 4 digits, you'll need 12 microcontroller pins in total. Controlling the display in this mode is a bit tricky, as you'll need to continuously alternate between the different digits.
Luckily, there are libraries that can help:
- On Arduino: Use the SevSeg library.
- On the Raspberry Pi Pico: The PIO peripheral can take care of refreshing the display for you. See the examples below.
If you are out of microcontroller pins, consider using a 74HC595 Shift Register to drive the display.