Main Content

Use the Arduino Due to control a large LED flat panel display. And the software to create and solve mazes on it

Two years ago, I published a tutorial about building a 128 x 64 LED two color panel and controlling it with an Arduino Mega. It’s here: LED Flat Panel with Arduino MEGA. The most popular software I included with it was a sketch to create and solve mazes. In this tutorial, I will upgrade the system by changing the processor to an 84 MHz Arduino Due and also provide a lot of new information about the software required to build and solve mazes!

So this tutorial is divided into two parts - first a detailed discussion about how we create and solve mazes in software, and then in part II, I will discuss the construction and software to control the large LED panel using the Arduino Due.

Mazes
If you are interested in mazes, and the software to create and solve them, this section will be of interest. There are many ways to display a maze. If you are just interested in mazes, you may not want to tackle as much hardware as I will describe later in this project You could use a smaller LED display or perhaps a large OLED display. Whatever you choose, the software I describe in this section could be adapted to it, so don’t abandon the maze idea just because you don’t want to tackle this rather big display project.

The software included in the download does several things:

It builds a random maze from an array of 32 x 16 cells.
It creates a single random point of escape.
It places our searcher (red search token) at a randomly selected point in the maze.
It proceeds to run the maze and eventually escape.
It then shows you the unique path it found from the starting point to the point of escape.
It then creates a new random maze and repeats the process.
The maze itself is constructed inside an array of 32 x 16 cells. A single byte in memory defines the status of each cell. The first 4 bits define whether the North, East, South, and West walls are open to the adjacent cell or closed. Open is 1, while Closed is 0. The 5th bit called Active is set if the cell is currently on the active path of escape. The 6th bit is Visited which is set when a cell has been visited and is no longer a new path to search. (This is how the program marks and rejects a path that failed to lead anywhere.)

Creating a Maze
The make_maze routine builds a random maze. We want it to create what is called a “perfect” maze, meaning there is always a unique single path between any two points in it. The maze is created using what is called a regressive backtracking algorithm. Here’s how it works: We create a stack, which is a list of cells. It is initially empty. Add one cell to the stack, at random. Now choose that most recent addition to the stack, and carve a passage to any unvisited neighbor of that cell (at random from among neighbors), adding that neighbor cell to the stack. By “carve a passage”, I mean set the bits of both cells to show the wall between them is open. Now move to the new cell and repeat this process again and again. If there are no unvisited neighbors, remove the cell from the stack and backtrack until you find a cell with unvisited neighbors. Repeat this process until the stack is empty. Surprisingly, that is all that is required to create a “perfect” maze. It will always have a path between any two points, regardless of where we start and regardless of where we end. And that path will always be unique!

Our make_maze routine then picks a random spot on an outside wall and opens a path of escape. (The escape point is not truly random, as I only picked a few spots to set up as escape points, but it picks one of them at random.)”

Link to article