Snake library for Arduino and 7-segments display

View the Project on GitHub Liksu/7SegmentsSnake

The Arduino snake library

This library allows to run snake on 7-segments display driven by LedControl. It was made as ‘screen saver’ for idle mode in our product.


Library available in the library manager.
Also, you can find the latest version on github project release page.


#include <LedControl.h>
#include <Snake.h>

// connect display with LedControl
LedControl ledControl = LedControl(12, 11, 10, 1);

// create Snake instance
// parameters: ledControl (required), digitsCount = 4, delay = 400 ms
Snake snake(ledControl);

void setup() {
    // start snake

void loop() {
    // move snake




Make sure that you have LedControl and it was added to your project.

Add snake library to your project:

#include <Snake.h>

Create snake variable:

Snake snake(ledControl);

First parameter is required and should be the LedControl instance.
Also there are two optional parameters that you can pass to Snake constructor:

Like this:

Snake snake(ledControl);
Snake snake(ledControl, 2);
Snake snake(ledControl, 8, 100);

Snake library does not use real delay() call, so pause between movements are not blocking.

Prepare to start:


This command initialize position of snake’s head (put it to te display in random place) and make some other preparation before run.


You can choose two ways to move the snake. The first is to call snake.tick() on each iteration of main loop:

void loop() {

In this case, the snake will be automatically moved when delay will over.

The second way is to move snake manually via calling the snake.move() manually, when you need it.

Available methods


void start(bool resetHead = true);

Prepares snake to move.
Parameter resetHead defines do library need to re-generate head position or use existing. Using it as false allows to implement continue after pause behavior instead of restart.


void stop(bool hide = true);

Stops snake on display. If parameter hide will be true (default behavior), segments of the snake will be switched off. Otherwise, it just stops movements (exclude manually) and allows to implement pause.


void move();

Manually moves snake on display.
Do not use snake.enabled flag.


void tick();

Allows to check time and move snake in main sketch’s loop.

property snake.enabled

Type bool, represent state of snake.
if false, snake wont move on tick calls.
Managed by snake.start and snake.stop methods.



Make display similar to yours. And then customize the snake:



And here is your constructor:

Snake snake(ledControl);


Video of real usage



If you find an error or have any other questions, please open issue on the github project page. Or you can contact me using e-mail:

© 2019 Petro Borshchahivskyi