Arduino 7segment 4 digits display Library

Created with Sketch.

Arduino 7segment 4 digits display Library


As also being an IOT maker I came up with a project that I needed to display information on 7segment LED displays. I found a great tutorial in YouTube made by Kristian Blåsol about driving a 4 digit 7segment LED display screen with 2 HC595 shift registers.

Before that, I ‘ve tried many Arduino libraries regarding seven segment display and none of them seem to work, or was to complicated for me to play with more than 1 shift registers (HC595) and 1 7segment LED display with 4 digits.

The code and logic of Kristian Blåsol was very simple and understandable so a SevenSeg4D class was borne in order to make the things a bit simpler.

You can find the entire Arduino library at the following link:

SevenSeg4D Library methods

The class offers 4 public methods:

void shiftOutMsg(char *msg);
void shiftOutChar(unsigned char c, byte digitpos);
void scrollMsg(char *msg, ScrollDirection direction, long delayTime);
void setAllowFloat(bool value);

The first one takes a null terminated buffer of characters and displays them on the 4 digits LED screen and the second one can display only one character at the digit position of our choise. Although the library has not been tested with more than 2 shift registers and a 4 digit 7 segment LED screen it could work with no problems, as long as you respect the wiring as per the video below:

The scrollMsg function may scroll a message from Left2Right or Right2Left and at the given delay in milliseconds. An example was made at the video below:


For those who like a different wiring (e.g. have all common digit (D1..D4) pins connected to the 2nd shift register) the setAllowFloat function does that. Just call it in the setup() function of your sketch with a true parameter as in the following example:

void setup() {

You can find a demo of the above option in YouTube:

To initiate the class just apply the 3 Arduino pins (data, clock and latch pin) at which you connect your circuit and if you use common cathode or common anode for your 7 segment screen, like the example below:

SevenSeg4D disp(dataPin, clockPin, latchPin, Cathode);

or using the SPI contstructror:

SevenSeg4D disp(latchPin, Cathode);

where you define only the latch PIN. The data and clock PINs are defined automatically as per the SPI Arduino reference

The default constructor uses dataPin = 3, clockPin = 4, latchPin = 2 and an Anode common connection to the 7segment LED display.

About the author

Bill Rigas is a Web Developer – Designer and co-founder of EverFounders blog with many years of professional experience on making software for airline companies. Owner of Msc Information of Technology diploma from University of East London and many certifications from edx. Also a certified Unity game developer from Walker Boys studio.