Gabriel Ohnstad
All projects

Spring 2026 · ECEN 2370 Embedded Software Engineering

STM32 Battleship

Battleship on an STM32F429 Discovery board's touchscreen, written in C as my final project. It has a hunt-and-kill AI opponent, two-player hot-seat, and a hit heatmap that survives power cycles. Every line of the game code is hand-written by me, with no AI-generated code.

Embedded CSTM32F429InterruptsTimersInternal flashHardware RNGTouchscreen

The game

The course provided the display, touchscreen and SDRAM drivers. I wrote the game on top: board and ship models, placement with rotation and collision checks, the turn loop, a touch UI with on-screen buttons, and hit and miss animations. Players place three ships (4, 3 and 2 tiles) on a 7 × 7 grid. In two-player mode the attacker sees the opponent's board with unhit ships hidden and can flip to their own board.

The AI

The single-player opponent hunts with the STM32's hardware random number generator. Once it lands a hit, it switches to a kill mode that probes the four tiles around the last hit until the ship sinks, then goes back to hunting.

Using the hardware

The scoreboard is a heatmap. At the end of every game, each tile's hits are added to a running total that I erase and reprogram into the last sector of internal flash, so the data survives power cycles. The scoreboard screen draws the whole board as a color gradient of where ships get hit most.

Holding the blue user button for more than three seconds resets to the main menu from anywhere. A rising/falling-edge EXTI interrupt starts and stops TIM6, which counts whole seconds while the button is held. A quick tap does nothing, so the game can't be reset by accident.