Skip to content

Repository files navigation

🎮 Pico Memory Game 🧩

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.

Pico Memory Game hardware

Project Overview

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

How the Game Works

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

Game Flow

  1. The player starts the game using the start button.
  2. The game plays an introductory melody and LED animation.
  3. A sequence of colors is generated.
  4. The sequence is reproduced using LEDs and corresponding tones.
  5. The player repeats the sequence using the physical buttons.
  6. Correct rounds increase the sequence length.
  7. An incorrect input triggers the error melody and resets the game.

Hardware

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

Implementation

GPIO and Interrupts

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.

Finite-State Machine

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.

Audio Feedback

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

Sequence Difficulty

The sequence becomes progressively longer as the player succeeds, increasing the memory challenge throughout the game.

Technologies

  • C
  • Raspberry Pi Pico / RP2040
  • Raspberry Pi Pico SDK
  • GPIO
  • Hardware interrupts
  • CMake
  • GitHub Actions
  • Cppcheck

Repository Structure

.
├── .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

Building

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.

Continuous Integration

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.

Academic Context

Originally developed as a team project for an embedded-systems course at Insper.

Authors

About

Embedded memory game written in C for Raspberry Pi Pico, using GPIO interrupts, LEDs, push buttons, a buzzer, and a finite-state machine.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages