Project 02- Snake game for STM32F429-Discovery board

After first FFT project, I’ve decided to make a simple snake game. Basically I’ve made it in Labview first for my partial exam at the university. It looked great so why not port it also to STM32F429-Discovery board which has everything already prepared for us.

You just need USB OTG cable and external keyboard to drive snake and you are ready to play.

Snake game

Features

  • Works on STM32F429-Discovery board
  • Supports external keyboard using USB HID Host stack on STM32
  • Supports selecting different speeds
    • More speed, more points
  • Standard snake game mode
    • Your goal is to make snake larger as possible
  • Supports 2 game modes
    • Mode 0: If you hit wall, game is stopped
    • Mode 1: If you hit wall, snake will come out at the other side of game area
  • Supports pause mode

Keyboard buttons and actions

Keyboard style for this project is QWERTY. If you put keyboard correct to USB, then GREEN led will be on, to detect this.

To operate with snake game, you will need buttons below:

  • All characters are LOWERCASE
  • w‘, ‘s‘, ‘a‘, ‘d‘: move snake to direction you want
  • r‘: resets game and starts again
  • m‘: toggles game mode between Mode 0 and Mode 1
  • u‘,’i‘: changes snake speed
  • p‘: toggles pause mode

When gameover occurs to you for some reason, you can press ‘r‘ (reset) key to reset it.

Source code

Entire project and source codes are in the bottom download. If you have any problems with compile (you shouldn’t have), there is also Snake.hex file included in project.

Tell me your best result in comments 😉

tilz0R

Owner of this site. Application engineer, currently employed by STMicroelectronics. Exploring latest technologies and owner of different libraries posted on Github.

You may also like...

Read before commenting!

Before you make a new comment, make sure you agree with things listed below:

  • - Read post to make sure if it is already posted what you are asking for,
  • - Make sure you have the latest version of libraries used in your project,
  • - Make a clean and grammatically correct written message,
  • - Report as many details as possible, including what have you done so far,
  • - Do NOT post any code here. Use Pastebin,
  • - Do NOT post any error codes here. Use Pastebin,
  • - Specify STM32Fxxx family and used Discovery/EVAL/Nucleo or custom made board,
  • - Make sure your clock is set correct for PLL,
  • - If you are using my HAL drivers, please check this post how to start.
Comment will be deleted on breaking these rules without notification!