Introduction
When I built a MIDI backing track player for my hobby band, I wanted to show four pieces of information on the front panel: the song number, tempo, key, and current bar. I used 7-segment LED displays, often referred to as FNDs in Korea, so I could read these values at a glance while playing.
LCDs and OLEDs can display text, graphics, and menus with multiple levels. A 7-segment LED display is well suited to equipment that needs to show a few numbers in fixed locations, such as readings on an industrial instrument or settings on a controller. With labels and units printed on the panel, users can quickly find the value they need while operating the equipment.
This article explains how 7-segment LEDs form digits and covers static GPIO drive, BCD decoders, MCU multiplexing, and dedicated drivers. It concludes with the 12-digit TM1640 display in my MIDI backing track player.
I described how I built the player in this article.
Building a MIDI Backing Track Player for a Hobby Band
How 7-Segment LED Displays Work
Forming Digits with LED Segments
A 7-segment display has seven LED segments arranged in the shape of the digit 8. The top horizontal segment is a. The outer segments continue clockwise from b at the upper right to f at the upper left, with g in the middle. The decimal point, DP, is a separate LED at the lower right.
To display 1, turn on segments b and c. To display 0, turn on all six outer segments. To display 8, turn on all seven segments. Turning on only g produces a minus sign.

The figure below shows how a 7-segment display can represent the hexadecimal digits 0 through F.

Image source — Real Digital
Understanding Display Size
A size such as 0.56 inches refers to the digit height. On the front-view drawing, it is measured from the outer edge of the top segment a to the outer edge of the bottom segment d. For example, the Kingbright SC56-11EWA has a digit height of 14.22 mm (0.56 inches) and a package body measuring 12.7 mm wide × 19.05 mm high.
Use the digit height to compare the size of the displayed numbers. When designing the front panel, check the package dimensions and the positions of the digit and decimal point. For PCB layout, check the pin pitch and pin arrangement. For a package containing several digits, check the overall width and the spacing between digits as well.

Reference — Kingbright SC56-11EWA datasheet
Common Anode and Common Cathode
The LEDs in each digit share one terminal. A common-anode display connects all the anodes together. A common-cathode display connects all the cathodes together. This determines how the driver supplies or sinks current and which output level turns a segment on.
| Display type | Common terminal | How a segment turns on |
|---|---|---|
| Common anode | The shared anodes connect to the supply side. | The driver sinks current from the segment cathode. With direct GPIO drive, a low output turns the segment on. |
| Common cathode | The shared cathodes connect to the ground side. | The driver supplies current to the segment anode. With direct GPIO drive, a high output turns the segment on. |
Two displays with the same dimensions and appearance can have different common-terminal configurations or pinouts. Check the internal circuit and pin numbers as well as the mechanical drawing before choosing a part.

Image source and further reading — Common Anode and Common Cathode 7-Segment Displays
Driving Methods
Static GPIO Drive
For a single common-cathode digit, connect the common terminal to GND and each segment from a through g to a GPIO pin through its own current-limiting resistor. If the decimal point is needed, connect DP to another GPIO pin in the same way. The output pattern changes when the displayed digit changes. Each active segment stays on until the next update. This is called static drive.
Use one current-limiting resistor per segment. With one resistor at the common terminal, the current per segment and the brightness would vary depending on how many LEDs were on. For example, 1 uses two segments, while 8 uses seven.
To calculate the resistance, subtract the LED forward voltage and the voltage drop across the drive circuit from the supply voltage, then divide by the target current.
R = (VSUPPLY − VF − VDRIVE DROP) ÷ ITARGET
For example, assume a 5.0 V supply, a red LED forward voltage of 1.9 V, a drive-circuit voltage drop of 0.2 V, and a target current of 10 mA. The calculated resistance is 290 Ω. Choosing a standard value of 330 Ω gives approximately 8.8 mA under the same assumptions. The 1.9 V figure is the typical forward voltage of the Kingbright part introduced earlier at 10 mA. The 0.2 V drop is an assumption for this calculation. In an actual design, account for supply and LED forward-voltage variation, along with the GPIO output voltage under load.
When 8 and the decimal point are both on, the common terminal carries the current of eight segments. In this example, that adds up to about 70 mA. Check the MCU’s per-pin and total output current limits. If a switch controls the common terminal, check that it can handle the combined current.

Direct GPIO drive is simple for one digit, but adding digits increases the number of GPIO pins and resistors. With the decimal point included, each digit requires eight GPIO pins and eight resistors. Driving four digits independently requires 32 of each. That makes routing more complicated and leaves fewer GPIO pins available for buttons or communication.
Display brightness also depends on how much current the MCU can source or sink. If the required current exceeds the MCU’s limits, use an external drive circuit.
For a single decimal digit, a BCD decoder can reduce the number of GPIO pins needed for the seven segments from seven to four. The decimal point can be controlled through a separate GPIO pin.
Using a BCD-to-7-Segment Decoder
A BCD-to-7-segment decoder converts a decimal digit into segment signals. For example, when the input is 0101, the 4-bit BCD representation of 5, the decoder activates outputs a, c, d, f, and g.
TI’s CD4511B is a decoder with a built-in latch for driving common-cathode displays. Each output from a through g connects to the display through a current-limiting resistor. The chip also provides inputs for holding the BCD value, blanking the display, and lighting the segments for testing. The decimal point uses a separate signal.
A circuit that uses one CD4511B to keep one digit lit is also an example of static drive. To display different numbers on several digits, you can assign a decoder to each digit or add digit-selection circuitry and share the decoder outputs.

Image source — CD4511 – A BCD to 7-Segment Display Driver Chip
Reference — TI CD4511B datasheet
MCU Multiplexing
When several digits are needed, they can share the segment signals. Connect all the a segments together, all the b segments together, and so on. Control each digit’s common terminal separately. The MCU outputs the pattern for the first digit and enables that digit, then does the same for the second digit. Repeating this process rapidly is called multiplexing.
A basic four-digit circuit with decimal points needs eight segment signals and four digit-select signals. The digit-select circuit carries the combined current of the segments that are on. A transistor or MOSFET can be used where the current requires it.
| Display type | Digit-select circuit | Design checks |
|---|---|---|
| Common cathode | Low-side drive using an NPN transistor or an N-channel MOSFET to connect the digit to GND | Check the base resistor and saturation voltage for an NPN transistor. For a MOSFET, check its on-resistance at the available gate voltage. |
| Common anode | High-side drive using a PNP transistor or a P-channel MOSFET to connect the digit to the supply | When a 3.3 V MCU controls a 5 V display, check that the circuit can turn the switch fully off. |
The following circuit drives a two-digit common-anode 7-segment display.

The two digits share segment signals A through G, each with a 1 kΩ current-limiting resistor. The MCU alternates between the digits using DG1 and DG2. On the selected digit, only the segments driven low light up. When this process repeats quickly, both digits appear to be on at the same time.
In this circuit, Q1 and Q2 operate as NPN emitter followers. Driving DG1 or DG2 high selects the corresponding digit. While the digit is on, its common-anode voltage is lower than the MCU’s high output voltage.
Scan Frequency, Duty Cycle, and Brightness
A slot is the time allocated to one digit. If each of four digits has a 1 ms slot, the selected digit changes every 1 ms and each digit lights once every 4 ms. The frame period is therefore 4 ms, giving a frame frequency of 250 Hz.
If the circuit spends 0.05 ms of each slot switching digits and keeps the digit on for 0.95 ms, the duty cycle is the on-time divided by the full frame period.
Duty cycle = on-time ÷ frame period = 0.95 ms ÷ 4 ms = 23.75%
At a segment current of 10 mA during the on-time, the average current is approximately 2.38 mA. If adding digits reduces the duty cycle per digit, the average current decreases for the same peak current. Before increasing peak current to improve brightness, check the LED datasheet for allowable current, pulse width, and duty cycle. For example, the absolute maximum peak-current rating for the SC56-11EWA is specified at a duty cycle of 1/10 and a pulse width of 0.1 ms. The four-digit example uses a different duty cycle and pulse width.
Segment Codes and the Display Buffer
In firmware, you can assign segments to bits, for example bit 0 = a, bit 1 = b, through bit 6 = g and bit 7 = DP. If a bit value of 1 means the segment is on, the pattern for 0 is 0x3F, the pattern for 1 is 0x06, and the pattern for 8 is 0x7F.
#include <stdint.h>
/* Bits 0–6 map to a–g. Bit 7 maps to DP. A set bit means on. */
static const uint8_t digit_segments[10] = {
0x3F, 0x06, 0x5B, 0x4F, 0x66,
0x6D, 0x7D, 0x07, 0x7F, 0x6F
};
When the value changes, convert each digit to a segment code and store it in the display buffer. A timer controls how often the firmware reads the buffer and outputs the pattern for the next digit. If a low GPIO output turns a segment on, as in the common-anode circuit above, use the appropriate polarity when writing to the output pins.
The firmware example below alternates between the ones and tens digits every 5 ms. It uses ch_table to look up the segment pattern for each digit and writes the output to P3OUT.

Reference — Microchip AN529 — Four-Digit LED Multiplexing Example
Ghosting and Blanking
If the firmware outputs the next digit’s segment pattern while the previous digit is still enabled, segments that should be off can light up briefly. The resulting faint pattern is called ghosting.
When switching digits, turn off the current digit, update the segment pattern, and then turn on the next digit. If the digit-select switch takes time to turn off, allow a short interval with all digits disabled before changing the segment signals. This interval is called blanking. If ghosting remains, use an oscilloscope to observe the segment and digit-select signals together. Look for delayed turn-off or unintended discharge paths through parasitic capacitance.
The timing diagram below shows the segment pattern being updated while both digits are off to reduce ghosting during the transition.

Reference — Analog Devices — Eliminating Ghost Currents in Multiplexed LED Displays
Using a Dedicated Display Driver
TM1640 Display RAM and Internal Scanning
The TM1640 drives common-cathode LED displays. According to the Titan Micro Electronics V1.0 datasheet, it supports up to 16 digits using outputs SEG1 through SEG8 and GRID1 through GRID16. The MCU sends display data to the TM1640, which stores it in internal RAM and scans the digits continuously. The MCU updates the data when the displayed value changes.
In a typical circuit, SEG1 through SEG8 connect to the shared a through g and DP lines. Each GRID output connects to one digit’s common cathode. Display RAM addresses 0x00 through 0x0F correspond to GRID1 through GRID16. Bits 0 through 7 in each byte correspond to SEG1 through SEG8. If the PCB uses a different segment or digit order, account for that mapping in firmware.
The MCU communicates over two signals, CLK and DIN. The TM1640 reads data on the rising edge of CLK. The firmware sets the data write mode, sends the starting address and segment data, and then sets the display on/off state and brightness. There are eight brightness levels, which change the on-time within a scan slot. The datasheet shows a display cycle with 16 GRID slots, so connecting 12 digits does not by itself establish a duty cycle of 1/12 per digit.
The following schematic shows the TM1640 display circuit used in my MIDI backing track player.

The player uses four three-digit FND modules for a total of 12 digits. The four modules share signals A through G and DP. Each digit’s common cathode connects to one of the TM1640 outputs from GRID1 through GRID12. The TM1640 selects each digit in sequence and outputs its segment pattern.
Level Shifting for a 3.3 V MCU
The TM1640 is a 5 V LED driver. Its operating supply range is 4.5–5.5 V, and the minimum input-high voltage for CLK and DIN is 0.7 × VDD. With the TM1640 running at 5.0 V, both inputs need at least 3.5 V to register a guaranteed high.
To meet this input requirement with a 3.3 V MCU such as the ESP32-S3, use 3.3 V-to-5 V level shifting on both CLK and DIN. Both signals travel from the MCU to the TM1640, so a unidirectional level shifter can be used. The MCU and TM1640 share a common ground.

In the MIDI backing track player, I used a PCA9306 to shift both signals. On the MCU side, SCL and SDA have 3.3 V pull-ups. The 5 V pull-ups for CLK and DATA on the TM1640 side are shown in the display schematic above. SCL and SDA are the signal names used in the schematic. They carry the signals to CLK and DIN, respectively, on the TM1640.
Reference — Titan Micro Electronics TM1640 V1.0 datasheet copy
Comparing Direct MCU Drive and Dedicated Drivers
With direct MCU multiplexing, the firmware controls digit selection and on-time. With a dedicated driver, the MCU sends display data and the driver handles the repeated scanning. When designing a 12-digit display, check how many MCU signals are required, how many digits each driver can handle, which interface it uses, and what logic levels it requires.
| Driving method | MCU interface | 12-digit configuration and design checks |
|---|---|---|
| Direct MCU multiplexing | Eight SEG signals and 12 digit-select signals, for a total of 20 in the basic circuit | The MCU controls scanning and brightness. Check GPIO current, external switches, scan timing, and blanking. |
| TM1640 | Dedicated two-wire serial interface with CLK and DIN |
One chip supports up to 16 common-cathode digits. With a 5 V driver supply and a 3.3 V MCU, level shifting is required. |
| MAX7219 / MAX7221 | Serial interface with DIN, CLK, and LOAD or CS |
Each chip supports up to eight common-cathode digits. Two chips can be daisy-chained. The minimum input-high voltage is 3.5 V. Analog Devices datasheet |
| HT16K33A | I²C with SDA and SCL |
The driver has 16 ROW and eight COM outputs. With one COM connected to each common-cathode digit, a 12-digit display requires two chips. Check the I²C pull-up voltage and logic levels with the driver’s 4.5–5.5 V supply. Holtek datasheet |
| MAX6954 | SPI-compatible serial interface | One chip supports up to 16 common-cathode 7-segment digits. The manufacturer lists the part as Last Time Buy, so check availability for a new design. Analog Devices product page and datasheet |
Application Example — ESP32-S3 MIDI Backing Track Player
In my MIDI backing track player, I used one TM1640 to drive 12 digits. The front panel gives the song number, tempo, key, and bar information their own fixed locations.
| Label | Position | What it displays |
|---|---|---|
| SONG | Top | Selected song number |
| BPM | Center | Current tempo setting |
| KEY | Lower left | A number representing the musical key |
| BAR | Lower right | Time signature while idle and current bar during playback |
The song number and BPM can be displayed directly. A key name such as C♯ is hard to read on a 7-segment display, so I assigned 1 to C, 2 to C♯, and continued in semitone steps up to 12 for B. While the player is idle, the BAR field displays the time signature, for example 404 for 4/4. Once playback starts, it shows the current bar number.
To prepare the display data, the firmware first decides what each field should show. For example, displaying song 001 requires converting both leading zeros into segment patterns as well. The value placed in the BAR field depends on whether the player is idle or playing. The player firmware applies these display rules and sends the segment data, while the TM1640 continuously scans the 12 digits.
Here is the assembled MIDI backing track player.

Conclusion
A 7-segment LED display is a good fit when equipment needs to show a fixed set of values that users can read quickly. For one digit, static GPIO drive offers a simple circuit. A BCD decoder is useful when the input is already in BCD. For several digits, available GPIO pins and the firmware workload help determine whether to scan the display directly or use a dedicated driver.
For the MIDI backing track player, I wanted the song number, BPM, key, and bar to appear in fixed locations. I assigned them to four fields on the front panel and used the TM1640 to scan all 12 digits. An LCD or OLED is more suitable for equipment that needs to display long messages or menus with several levels. Start with what users need to see and how quickly they need to read it while operating the equipment. That helps determine the digit size, number of digits, and driving method.