This project implements the game Snake for an ESP32 microcontroller, written in Rust.
This was written as a basic starter project.
Hardware:
Photo:
Video:
output.mp4Wokwi project (note does not build there due to Rust dependencies): https://wokwi.com/projects/413450202628576257
Embassy is used to run concurrent tasks (checking for input at a faster rate than the game update rate).
The joystick URX and URY axes inputs are handled with a built-in Analogue-Digital Converter (be careful about the choice of GPIO pins as the selection is limited). And the button click is handled with an interrupt.
DeploymentInstall Rust and espup.
Then run:
$ source ~/export-esp.sh $ cargo run --releaseSimulation
Install Wokwi for VS Code. Open diagram.json and click Play button.
NotesNote the input voltage to the joystick had to be lowered via a voltage divider to get a usable range, the voltage divider here used one 1k and one 2k Ohm resistors to the 5V input.
Note the SCL and SDA pins to the I2C display needed pull-up resistors, here I used 2k Ohm resistors to 5V.
Known IssuesThe use of the buffered graphics mode means that the display becomes laggy for longer snake sizes. This could be reduced by using direct draws (to not redraw the whole screen) and increasing the baud rate of the I2C connection.
Food can spawn next to the snake which is confusing on the monochrome display (and can result in instant victory too).
The game is very easy on the current size / speed.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4