Over a million developers have joined DZone.
Platinum Partner

Snake Game on the FRDM-KL25Z with Nokia 5110 Display

· IoT Zone

The IoT Zone is brought to you in partnership with ThingWorx. Explore the ThingWorx Developer Zone and learn how to rapidly develop IoT applications.

So I have a graphics driver for a Nokia display (see “Zero Cost 84×48 Graphical LCD for the Freedom Board“), I have a joystick shield (see “JoyStick Shield with the FRDM Board“) and I do have a Freescale Freedom board: why not creating a simple game for it? Snake!

Snake Game with FRDM-KL25Z Board

Snake Game with FRDM-KL25Z Board

My first mobile phone was a Nokia with a 84×48 black/white display, and I loved it for many reasons, including having the ‘Snake’ game (see http://en.wikipedia.org/wiki/Snake_%28video_game%29). An ARM Cortex M0+ is way overpowered for that simple game, still it is fun to make and game it :-).

The game is very simple: A snake is running around, and I can control it with the cursor/joystick with up, down, left and right. The snake has to ‘eat’ the ‘food’, and the snake gets longer the more food is eaten. But the snake shall *not* touch the outside border.

:idea: Usually there is another rule that the snake shall not touch itself. But I was too lazy to make it.

Snake with Food

Snake with Food

For the project I ordered a black joystick shield for $11.27, as the soldering quality of the previous ‘white’ one was very bad. The Nokia 5110 LCD I ordered from DX.com for $3.87 so it would directly match with the joystick shield. So makes $30 in total including the FRDM-KL25Z board.

Startup Screen for Snake Game

Startup Screen for Snake Game

Ready to Play Snake Game

Ready to Play Snake Game

The video shows the game in action:

The Snake game runs as a FreeRTOS task. The drawing and graphics including fonts are implemented with Processor Expert components:

Graphical Display Driver

Graphical Display Driver

Font and Font Driver

Font and Font Driver

Summary

So I have another nice usage for my boards and the joystick shields :-). I need to admit that I’m not very good at the game. My daughter reached level 4 in the first attempt, while my max level is 2, maybe it is just the age ;-). But I’m too honest *not* to build in a cheat mode, or should I? Maybe ;-)

As always, the sources are available on GitHub.

Happy Snaking :-)



The IoT Zone is brought to you in partnership with ThingWorx. ThingWorx is the most complete application development platform available that is purpose-built for the IoT.

Topics:

Published at DZone with permission of Erich Styger , DZone MVB .

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}