The hardware is really simple for this. The display is hooked up to ESP32 default hardware i2c GPIOs. and the buttons are hooked up directly to GPIOs on one side and ground on the other side.
The Arduino Code is available on github. I've tried to make the code as modular as possible, but I am not a regular c++ user so you may see some oddities there. The main components are:
- button.h/cpp -- handles buttons using interrupts. Probably the most interesting one for me as I didn't want to duplicate the interrupt routines so ended up having to make a monster macro for the first time in my life
- fruit.h/cpp -- holds the position of the fruit and can pick a new location on the board without overlapping the snake
- position.h/cpp -- helper data structure as c++ doesn't have touples
- renderer.h/cpp -- does all the rendering of the game, if you want to port the game to use a different display these are the only files you'd have to swap out.
- snake.h/cpp -- holds the information about the snake, where it is, and methods to move it around.