loading

We demonstrated how an Arduino based Bi-color LED Matrix Tetris Game can be built in our last instructable. We were quite surprise it was featured to the Instructables homepage and have garnered quite a handful of favourites over a short period. You may check it out if you are interested at https://www.instructables.com/id/Arduino-based-Bi-color-LED-Matrix-Tetris-Game/.

When we were young, there were not many electronic games around and one of the games we enjoy playing on those monochrome monitor with green phosphor screen is the Snake game. For this instructable, we will be building the classic SNAKE game using Bi-color LED Matrices powered by Arduino.

Before we decide to come up with this instructable, we browse through the existing instructables to check if there are any similar projects. Indeed we found a couple of instructables implementing the game, some using the Rainbowduino driving an RGB LED Matrix from Seeedstudio.

We decided to go ahead with our instructable to build the Snake game using our jolliFactory Bi-color LED Matrix Driver module DIY kit. This LED matrix Driver module is designed to be modular and chain-able so that you may daisy-chain the modules together to the number of modules you need to suit your project. We actually re-used these modules here by dis-assembling them from one of our old Scrolling Text Display project. You may visit https://www.instructables.com/id/Arduino-SPI-7-Bi-color-LED-Matrix-Scrolling-Text-D/ if you are keen on building one of these displays.

If you have built the Bi-color LED Matrix Tetris game based on our last instructable, you may proceed directly to the Programming the Arduino Board step to download the Arduino sketch and enjoy the Snake game. For this game, we will only be using 2 push buttons (Left and Right) for game navigation as we think it will be more challenging than using 4 push buttons. We are able to produce dots with red, green or orange on the display by using the Bi-color LED Matrix which should be sufficient for this simple game. We will have orange color for the snake head, red for the snake body and green for the food/token.

To build this project, basic electronics knowledge with electronics component soldering skill and some knowledge on using the Arduino are required.

You may view the following YouTube video to see what we are building.

We will be repeating some of the steps from our Tetris game instructable here to make this instructable as complete by itself without reference to another instructable.

Step 1: Building the Arduino Bi-color LED Matrix Snake Game

We will be building a two LED Matrix tall Snake game here driven by an Arduino Nano. We will need two of the Bi-color (Red/Green) LED Matrix Driver Module Kits from jolliFactory. Each of these modules uses two MAX7219 Display Driver ICs to drive a Bi-color LED Matrix. These ICs are excellent because they take a lot of work off the micro-controller and simplify the wiring and logic design.

You can find this Bi-color LED Matrix Driver Module kit here.

This kit comes with all through-hole components and someone with basic soldering skill should be able to assemble it without much difficulty.

See the following YouTube video on how to assemble the LED Matrix Driver Module Kit:


Step 2: Wiring

After the two LED Matrix Driver Module kits are completed, they are connected together with the Arduino Nano micro-controller as shown in the wiring diagram (LED Matrices not installed for better view).

For the game audio output, we used one 8 ohms 0.5 watt speaker driven
directly by one of the Arduino’s digital pins through a 100 ohms resistor. Basic sound tone is used for this project and the low sound volume should be sufficient for a hand-held game with this simple setup.

Two panel mount momentary push button switches are required for the project for controlling the movement of the snake.

Note the use of 10Kohms pull-down resistors on the DATA IN, CLK and LOAD input pins. When power is first applied to the micro-controller or when they are reset, their I/O lines float. The MAX7219 can see this as valid data and display garbage until the micro-controller gains control. The pull-down resistors prevent these problems. To reduce the part count for this project, you may try without the 10Kohms pull-down resistors for the DATA IN and CLK input lines.

Except for the two Bi-color LED Matrix Driver modules and the two push button switches, we hook up the entire circuit on a small piece of perf-board around 60mm x 60mm in size.

Note that there are two PCB mount push buttons on the perf-board. We initially used them for the game control but after building a simple enclosure for the game, we decided to use two panel mount push buttons instead for better game control. We parallel wired our panel mount push button with the PCB mount push buttons so game control can now be performed using either the PCB or panel mount push buttons.

Step 3: Programming the Arduino Board

The Arduino board needs to be loaded with the Arduino sketch to run the game.

We used Arduino IDE V1.03 for our project. Download the Arduino sketch below for this project and upload it into your Arduino board.

Download jollifactory_Snake_V1_0.ino

We adapted the snake game sketch found at http://forum.arduino.cc/index.php/topic,8280.0.ht... to work with our jolliFactory Bi-color LED Matrix Driver Module for this project.

The sketch uses the SPI and Bounce2 libraries. The SPI library comes with the Arduino IDE V1.03 installation and Bounce2 library can be found at http://playground.arduino.cc/Code/Bounce

We have coded the Arduino sketch so that if you would like to build a single bi-color LED Matrix Snake game, you simply need to change the variable bi_maxInUse from 2 to 1, upload the sketch and enjoy the game.

The Snake game sketch we have here is very basic without any game levels and scores. You may amend and enhance the sketch to your liking.

Step 4: Enclosure and Assembly

We will re-use the hand-held enclosure we built for our last Tetris game instructable here as basically there is no change to the project module form factor. As this project is also build just for the FUN factor with no intention of using it for long, we do not want to put in too much effort to build a proper enclosure. However, the enclosure built should enable the player to hand-held it to play quite comfortably.

What we have for the enclosure is a cardboard box backing with a blue tinted acrylic protective front with the game control push button switches mounted. We did not even secure the modules to the enclosure as they fit quite snuggly in the enclosure.

We will not delve into the detail on how we build our game enclosure here. The pictures show the various stages of assembling the sub-modules together.

Step 5: Enjoy the Snake game

Playing the Snake game is easy.

  • Control the snake movement by activating either the Left or Right button.
  • Hunt for food/token and grow longer.
  • Do not let the snake bite itself.
<p>It looks great!</p>
<p>how could i do this with a 10x10 WS2812B rgb matrix?</p>
<p>very good project by the way :O</p>
<p>Hello please ask how to connect 2 led matrixes each other? </p>
<p>Are you using the Bi-color LED Matrix modules from </p><p><a href="https://www.tindie.com/products/Nick64/60mm-x-60mm-bi-color-led-matrix-driver-module-diy-kit/." rel="nofollow">https://www.tindie.com/products/Nick64/60mm-x-60mm...</a>?</p><p>If so, the LED Matrix modules can be connected easily by just plugging one module to another via the connectors at the sides of the modules.</p><p>You may plug more LED Matrix modules together to make a longer display for projects such as a scrolling text display found at </p><p><a href="https://www.instructables.com/id/Arduino-SPI-7-Bi-color-LED-Matrix-Scrolling-Text-D/" rel="nofollow">https://www.instructables.com/id/Arduino-SPI-7-Bi-c...</a></p>
<p>We have used one color led matrix and we have connecting matrixes each other by plugging one module to another via the connectors, but they are doing the same thing, What shall we do?</p>
<p>The Arduino sketch we have here works with Bi-color LED Matrix modules and will not work with a single color LED Matrix. You may need to modify the sketch for it to work with single color LED Matrix but it may not be easy if you are not familiar with programming. It should not be difficult to find a snake game running using single color LED Matrix if you search online.</p>
<p>Thank you for help.</p>
<p>For those who are unable to locate the bounce2 library, I have amended the link in Step 3 to go to the download page for this library.</p>
<p>Hi, me again, would you mind explaining what this part of the code does?:</p><p>#include &lt;SPI.h&gt; </p><p>#define GREEN 0 </p><p>#define RED 1 </p><p>#define offREDoffGREEN 0</p><p>#define offREDonGREEN 1</p><p>#define onREDoffGREEN 2</p><p>#define ISR_FREQ 190</p><p>thanks, I am trying to recreate your project because its really cool!</p>
<p>Thanks for your interest in this project. This project's coding is not for beginners. You may need to check out more basic Arduino project tutorials first to be able to follow through the codes here.</p><p>Basically, the 'include' statement here is to use the SPI library so that we can use the available SPI library functions and routines such as SPI.transfer in our code without writing our own functions and routines.</p><p>All the 'define' statements are used for ease of reading the codes. For example, #define offREDonGREEN 1 is used so that whenever you see the term offREDon GREEN in the code, the program actually replaces it with 1.</p>
<p>would this work with a regular arduino? (arduino uno)</p>
<p>Sure. Arduino UNO works perfectly with this instructable.</p>
Good stuff! Love it.

About This Instructable

21,360views

67favorites

License:

More by jollifactory:JolliCube Audio/Music Visualizer JolliCube (8x8x8 LED Cube) with MD_Cubo library Arduino Based Mini Audio Spectrum Visualizer 
Add instructable to: