Conway's Game of Life with an Arduino and an 8x8 LED Array


A few days ago I picked up Turtles, Termites, and Traffic Jams by Mitchel Resnick. The book covers the educational potential of programming cellular automata like Conway’s Game of Life using a programming language called StarLogo. I’ve long been interested in Conway’s Game of Life, and the book inspired me to implement it myself.

Back in 2014 I ordered an 8x8 LED array and a MAX7219 multiplexer to control it. My plan was to use it to create a small representation of Conway’s Game of Life. But at the time this was way over my head. I didn’t really know how to program and wasn’t very good at soldering, which are the two critical components of the project.

Now, five years later, the project only took a few hours of planning, soldering, and coding. In retrospect I probably could’ve managed it five years ago, but it would’ve taken me much, much longer.

conway schematic I used this diagram to keep track of how to connect the multiplexer to the 8x8 LED display.

The basic process was to connect my Arduino to the multiplexer, and the multiplexer to the LED display via jumper cables. This was the hardest part, since the data sheets for the two devices don’t describe how to connect them, and the one guide I did find has a different pin numbering scheme.

8x8 led display running This is part of an example script which I used to verify that I’d connected the multiplexer and display correctly.

I did get it sorted out, though, and once I’d verified that I had the pins connected correctly I replaced the breadboard with a protoboard and the jumper wires with hook-up wire. Here’s the final result:

soldered 8x8 The final product, displaying a starting point for a Game of Life. I don’t have a picture of it, but the back of the board is where most of the hookup wire goes.

The idea behind Conway’s Game of Life is that each cell (or pixel, or LED) represents an organism. These organisms live or die (turn on or off) based on the surrounding cells. Too many and they die off from “overpopulation,” too few and then die from “loneliness.”

Once a randomized environment is created at the beginning of the program, it goes through a simple loop: update environment based on previous generation, display on LED array, repeat. Here’s how I implemented the rules described by Conway:

// Update newMap according to Conway's rules
int numNeighbors = countNeighbors(oldMap,col,row);
if (oldMap[col][row] == true && numNeighbors < 2) {
    newMap[col][row] = false;
} else if (oldMap[col][row] == true && (numNeighbors == 2 || numNeighbors == 3)) {
    newMap[col][row] = true;
} else if (oldMap[col][row] == true && numNeighbors > 3) {
    newMap[col][row] = false;
} else if (oldMap[col][row] == false && numNeighbors == 3) {
    newMap[col][row] = true;
}

Initially I thought about encoding each “generation” as a 64-bit integer (since there are 64 LEDs in the array), but I ended up just using a two-dimensional array since I wasn’t as crunched for space on the Arduino as I thought I’d be. The whole program, which you can see here, totaled just 2 kilobytes.