An embedded sequence-memory game written in C for the Raspberry Pi Pico, using physical push buttons, LEDs, a buzzer, GPIO interrupts, and a finite-state machine.
The player watches a sequence of colored lights and tones, then reproduces it using the corresponding buttons. The sequence grows as the player progresses, increasing the difficulty until an incorrect input triggers the game-over state.
This project was developed as an embedded-systems assignment and combines software logic with direct hardware interaction.
The implementation demonstrates:
- GPIO input and output using the Raspberry Pi Pico SDK
- Interrupt-driven button input
- LED and buzzer control
- Sequence generation and validation
- Finite-state-machine design
- Timing with the Pico SDK
- Modular C code using header and source files
- CMake-based embedded builds
- Automated build and static-analysis checks with GitHub Actions
The game follows a state-machine architecture:
INITIAL_STATE
|
v
SORT_STATE
|
v
SHOW_STATE
|
v
PLAY_STATE
/ \
correct wrong
| |
v v
SORT_STATE GAME_OVER
|
v
INITIAL_STATE
- The player starts the game using the start button.
- The game plays an introductory melody and LED animation.
- A sequence of colors is generated.
- The sequence is reproduced using LEDs and corresponding tones.
- The player repeats the sequence using the physical buttons.
- Correct rounds increase the sequence length.
- An incorrect input triggers the error melody and resets the game.
| Component | GPIO |
|---|---|
| Red LED | 13 |
| Green LED | 12 |
| Yellow LED | 11 |
| Blue LED | 10 |
| Red button | 22 |
| Green button | 21 |
| Yellow button | 20 |
| Blue button | 18 |
| Start button | 19 |
| Buzzer | 15 |
Buttons are configured as GPIO inputs with pull-up resistors. Button presses are detected through falling-edge GPIO interrupts and handled by a callback function.
gpio_set_irq_enabled_with_callback(
BTN_PIN_INI,
GPIO_IRQ_EDGE_FALL,
true,
&btn_callback
);The interrupt callback records the detected input, which is later evaluated by the game logic.
The main game behavior is separated into five states:
| State | Responsibility |
|---|---|
INITIAL_STATE |
Initializes a new round and plays the startup feedback |
SORT_STATE |
Adds new values to the sequence |
SHOW_STATE |
Displays the current sequence through LEDs and sound |
PLAY_STATE |
Reads and validates player input |
GAME_OVER |
Plays error feedback and resets the game |
This structure keeps game progression separate from hardware initialization and input handling.
Each color has a corresponding tone generated through the buzzer.
The project also includes:
- An introductory melody
- Individual button tones
- A descending game-over melody
The sequence becomes progressively longer as the player succeeds, increasing the memory challenge throughout the game.
- C
- Raspberry Pi Pico / RP2040
- Raspberry Pi Pico SDK
- GPIO
- Hardware interrupts
- CMake
- GitHub Actions
- Cppcheck
.
├── .devcontainer/
├── .github/
│ └── workflows/
│ ├── build.yml
│ ├── cppcheck.yml
│ └── embedded-check.yml
├── docs/
│ └── pico-memory-game.jpeg
├── main/
│ ├── CMakeLists.txt
│ ├── funcoes.c
│ ├── funcoes.h
│ └── main.c
├── .gitignore
├── CMakeLists.txt
├── pico_extras_import_optional.cmake
├── pico_sdk_import.cmake
└── README.md
The project requires the Raspberry Pi Pico SDK and a compatible ARM toolchain.
After configuring the Pico SDK environment:
mkdir build
cd build
cmake ..
cmake --build .The generated firmware can then be copied to the Raspberry Pi Pico in bootloader mode.
The repository contains GitHub Actions workflows for:
- Building the Raspberry Pi Pico project
- Static analysis with Cppcheck
- Embedded-code checks
These checks help validate the project automatically after pushes to the repository.
Originally developed as a team project for an embedded-systems course at Insper.
- Marinna
- Verônica Luisa Ribeiro Lima
