Have you played snake game at least once in your life?
OK, even though snake game may not be popular today, it is still one of the greatest games made by Nokia. So, how cool is it if you can make your own snake game with some simple electronic equipment and basic knowledge of electrical engineering. For that reason, I made a snake game with a matrix led module when I studied micro-controller subject in third year at university.
Let me introduce a bit of information about this project.
First thing I want to show you is devices I used to build the project.
- Tiva C Launchpad (it sounds unreasonable when I used an ARM platform just to implement a small project. OK, the reason is to learn this powerful weapon).
- A keypad (I know it was not an optimal option, some people may use joystick to make the project cooler).
- A matrix led module was used as a screen to display the position of snake and fruit (in this project, I used 8×8 module, some people may want to use larger module).
- Electrical source.
When all devices were prepared, in the next step, let me show you the strategy I used to make the snake move.
Fig. 1. The imagined coordinate on the matrix led module
Imagine we have a 2D Cartesian coordinate as the Fig. 1 and every led in the matrix module is considered as a unit in this coordinate.
- For the snake:
- I initialized two arrays (including x-array and y-array) to save x and y coordinate of the snake. In which, (x, y) is the position of snake’s head on the screen and the rest of elements in these arrays are the positions of snake’s body parts.
- In the project, my purpose was to control the snake’s head by keypad, snake’s body parts were programmed to track its head.
- On the other hand , a variable is declared to save the length of the snake. It was limited within 15 points (i.e. the maximum length of the snake was 15 points on the screen).
- For the fruit: I made two other variables to save the position of the fruit. These two variable get the value from a random function which is support by TI library.
And this is my results.
I hope you enjoy it,