The goal of this project was to implement the classic Snake game on a microcontroller using an SPI-based 1.3" TFT LCD display (ST7789). The game is controlled via an analog joystick and visually rendered in full color. The snake grows longer each time it eats food, and the game ends either when the snake collides with itself or the wall. If the snake reaches the maximum possible length (filling the entire screen), a different ending animation is triggered. The project emphasizes embedded system programming, graphical rendering on an LCD screen, timer-based task scheduling, and handling user input from external hardware components. Through this project, we aimed to integrate low-level peripheral control with real-time gameplay logic in a fun and engaging way.
Video |
The following components were used to compose game's PCB:
Board | Assembly | Schematic | ||
While our goal of this project is making a snake game, the hardware plays a critical role in bringing the game to life. The Silicon Labs EFR32BG22 microcontroller handles all core computations, including input processing, game logic, and communication with the display module. The 1.3" SPI TFT LCD, driven by the ST7789 controller, receives commands via the SPI interface to visually render the snake, food, and background. The analog joystick sends directional input as voltage levels to the ADC pins on the microcontroller, allowing the user to control the snake in four directions. The USB connection is used to power the board as well as to flash and debug the firmware during development. Together, these components work seamlessly to create a responsive and visually engaging embedded game system.
The snake game software was written in C using Silicon Labs' Simplicity Studio IDE. Two hardware timers are used: one polls the joystick every 10 milliseconds, and the other updates game logic every 300 milliseconds. The joystick input controls the snake’s direction, and all movement, collision detection, and food generation are handled in real time. The ST7789 LCD is updated using pixel-based drawing functions, and the game resets automatically if the snake hits a wall or its own body. The score is updated visually after each successful food collection. New random food position is generated by using on-board True Random Number Generator (TRNG).
The final version of the snake game successfully displays real-time gameplay on the 1.3" SPI TFT LCD with a resolution of 240x240 pixels. The snake moves smoothly across the screen, and its direction responds accurately to joystick input. The food appears at random positions that do not overlap with the snake's body, and when the snake consumes the food, its body length increases correctly. Collision detection with both the walls and the snake's own body works as expected, and the game resets automatically with a flashing red screen to indicate failure.
The visual quality of the TFT display significantly enhances the user experience compared to simpler LED matrices. The platform can be used for implementing other games.