TM1637 display/How it shows a number/06. Seven segments, one byte
How it shows a number · 06 of 13

Seven segments, one byte

A digit is one byte: bit 0 is the top bar, bit 6 is the middle one, bit 7 is the point. Once you can write that byte yourself, the display shows things that are not numbers — a dash, a degree sign, the word done.

The byte

Seven bars, a point, eight bits. The library counts them in the order they come off the chip: bit 0 is segment A, the top bar, and bit 6 is G, the middle one. Bit 7 is the decimal point, or on a clock panel the colon.

One digit, one byte
0x6D
Turn a segment on or off
Or start from one of these
The byte
0x6D
In binary
0b01101101
The library calls it
encodeDigit(5)
Bit 0 is segment A, bit 6 is G, bit 7 is the point. That is the whole alphabet of this display: any pattern you can make from seven bars, and setSegments() takes four of these bytes. It is how you write donE or ---- or a degree sign. It is also why you cannot write M, W, K, X or V — no arrangement of seven bars makes them, and a display that could is a dot-matrix, not this.

0b01101101 is 5. There is nothing more to it than that, and the library's whole digit table is sixteen of these bytes, one for each of 0–9 and A–F.

Writing it yourself

setSegments takes an array of these bytes and puts them on the display.

const uint8_t DONE[] = { 0x5E, 0x5C, 0x54, 0x79 };   // d o n E
display.setSegments(DONE);

It also takes a length and a starting position, which is how you change part of the display and leave the rest alone:

display.setSegments(DONE, 2, 0);        // the left two digits only
display.clear();                        // all four off

Two patterns worth keeping:

const uint8_t DASHES[] = { 0x40, 0x40, 0x40, 0x40 };   // ----  : no reading yet
const uint8_t DEGREES  = 0x63;                          // °     : after a temperature

---- is the honest thing to show while a sensor is warming up or a clock has not yet been set — an old reading left on the display is indistinguishable from a current one.

What it cannot show

Seven bars make every digit, and about eighteen letters if you are generous, and no amount of cleverness makes M, W, K, V or X. Some letters only work in lower case: b and d have to be, because capital B and D would be identical to 8 and 0.

This is the real limit of the part, and it is worth knowing before you design something around it. A display that has to say PUMP OFF is a matrix display or an LCD. A display that has to say 23.5 or 12:00 or Err is this one, and this one is legible across a room in a way the alternatives are not.

When it does not work

SEG_DP was not declared in this scope

The released library defines SEG_A to SEG_G and stops. SEG_DP only exists on the project's unreleased master branch, so example code that uses it will not compile against the version the Library Manager installs. Write 0b10000000 instead.

setSegments only changes some of the digits

That is what it is for. setSegments(data, length, pos) writes length digits starting at pos and leaves the rest alone, so a display can be updated in two halves. Pass no length and pos and it writes all four.

My word looks like nonsense on the display

Seven bars cannot make M, W, K, V or X, and the letters that do work are a mixture of capitals and lower case — b, d and o have to be lower case, because the capitals would be identical to 8, 0 and 0. Stick to short words that survive that.

Everything I write shows up one digit to the left

The pos argument is counted from the leftmost digit, 0 to 3, and it is the position of the first byte in your array. An array of three bytes at pos 0 fills the left three digits, not the right three.

Where this goes next

What showNumberDecEx does with a number, a mask and a leading-zero flag — including three things it does that nobody expects.

Numbers, points and the colon

Edit this page — content/books/tm1637-display/seven-segments-one-byte.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

This page covers several products. Choose yours to see the right discussions.

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum