Proje Defteri

🔢 7 Segment Display Code Generator

Pick a character and instantly get its segment byte for Arduino as binary, hex and decimal. Common cathode/anode and decimal point support — everything runs in your browser.

Supported characters: 0-9, A-F, H, L, P, U and dash (-). You can also use the buttons below.
Common anode is the bitwise NOT of the common cathode code.
Default: bit 0 = a, bit 7 = dp. Change to match your hardware.
When ticked, the top bit (dp) of the byte is set to 1 (+0x80).
—
Binary
—
Hex
—
Decimal
—

What is a 7 Segment Display Code Generator?

A 7 segment display is a simple readout made of seven LED bars (segments) arranged in a figure-8 plus an optional decimal point (dp), used to show digits and a few letters. This 7 segment display code generator works out which segments must light up for the character you pick and returns that as a single byte in binary, hexadecimal (hex) and decimal. It also builds an Arduino code line you can drop straight into a segments[] array in your 7 segment Arduino projects. All processing happens in your browser; no data is ever sent to a server.

Segment naming: a-g and dp

The seven segments are conventionally named a, b, c, d, e, f, g. Segment a is the top horizontal bar, b is top right, c is bottom right, d is the bottom bar, e is bottom left, f is top left and g is the middle bar. The decimal point is labelled dp. When we pack these eight LEDs into a single 8-bit byte, the arrangement that says which bit maps to which segment is called the bit order (segment map).

Bit/byte map — default dp-g-f-e-d-c-b-a

This tool uses dp g f e d c b a by default: the least significant bit (bit 0) is segment a, bit 6 is segment g, and the most significant bit (bit 7) is the decimal point (dp). So the byte is laid out as bit7=dp, bit6=g, bit5=f, bit4=e, bit3=d, bit2=c, bit1=b, bit0=a. For example, the character 0 lights every segment except g (a, b, c, d, e, f), which gives 0b00111111 = 0x3F = 63 on a common cathode display. If your segments are wired to different pins, switch the bit order to "a b c d e f g dp".

Common cathode or common anode?

There are two types of 7 segment display. In a common cathode part all LED cathodes share a common GND, so you light a segment by driving its pin 1 (HIGH). In a common anode part the anodes share a common +5V, so a segment lights with 0 (LOW). Because of this, the common anode byte is the bitwise NOT of the common cathode byte: anode = ~cathode. Use the "Display type" selector to flip between the two values instantly.

Example Arduino wiring and code

In a typical setup you connect the 8 segment pins (a-g + dp) through current-limiting resistors to 8 digital pins. Put the generated bytes in an array and write them to the pins in a loop:

// Common cathode, dp-g-f-e-d-c-b-a order
byte segments[10] = {
  0x3F, 0x06, 0x5B, 0x4F, 0x66,
  0x6D, 0x7D, 0x07, 0x7F, 0x6F
};
int pins[8] = {2,3,4,5,6,7,8,9}; // a..g, dp

void showDigit(int n) {
  for (int i = 0; i < 8; i++)
    digitalWrite(pins[i], bitRead(segments[n], i));
}

Tips

Frequently Asked Questions

What is the difference between common cathode and common anode?

In a common cathode display all LED cathodes share a common GND, and a segment turns on when its pin is driven 1 (HIGH). In a common anode display the anodes share a common +V, and a segment turns on with 0 (LOW). That is why the common anode code is the bitwise NOT of the common cathode code.

What is the bit order in the segment byte?

This tool uses the dp-g-f-e-d-c-b-a order: the least significant bit (bit 0) is segment a and the most significant bit (bit 7) is the decimal point (dp). So the byte reads dp g f e d c b a. If your hardware wiring differs you can switch the segment order.

How do I use the generated hex code in Arduino?

Store each character's byte in a byte segments[] array, then send the bits of that byte to your 8 segment pins in order (a through dp). Usually a for loop with digitalWrite writes each bit to its own pin; with a shift register (74HC595) you send it in one shiftOut() call.

How does the decimal point (dp) affect the byte?

Ticking the decimal point box sets the most significant bit (bit 7) to 1, which adds 0x80 to the hex value. For example the character '0' is 0x3F on a common cathode display, and 0xBF with the dp on.