Skip to content
Notifications You must be signed in to change notification settings

Hasona57/Hassan-Hackpad

Repository files navigation

Hassan's Hackpad - Memory Game

A Simon Says-style memory game built for embedded systems, featuring colorful NeoPixel LEDs, an OLED display, and multiple difficulty levels. Available in both Arduino C++ and MicroPython (Raspberry Pi Pico) implementations.

Hassan's Hackpad

Table of Contents

Overview

Hassan's Hackpad is an interactive memory game where players must watch a sequence of colored LEDs and repeat it back correctly. The game progressively increases in difficulty, testing your memory and reaction time. With multiple difficulty levels, score tracking, statistics, and practice mode, it offers a complete gaming experience on embedded hardware.

Features

  • 4 Difficulty Levels: Easy, Normal, Hard, and Extreme
  • Practice Mode: Learn without time pressure (sequence shows 3 times)
  • Score Tracking: Top 5 scores saved per difficulty level
  • Statistics: Track games played, average scores, and performance by difficulty
  • Visual Feedback: Rainbow animations, LED celebrations, and OLED display
  • Pause Functionality: Pause and resume games at any time
  • Quick Restart: Restart games immediately after game over
  • Persistent Storage: Scores and statistics saved to flash memory
  • Dual Implementation: Available in both Arduino C++ and MicroPython

Hardware Requirements

Components

  • Microcontroller:
    • Seeed Studio XIAO RP2040 (for C++ or python)
  • Display: 0.91" OLED Display (128x32 pixels, I2C)
  • LEDs: 4x NeoPixel LEDs (SK6812 MINI)
  • Buttons: 4x MX Cherry push buttons
  • Resistors: Pull-up resistors for SDA and SCL
  • Power: Supply by 3 AA battery holder (BC3AAAPC)

Pin Configuration

  • LEDs: GPIO 3
  • Buttons:
    • Button 1 (Red): GPIO 26
    • Button 2 (Blue): GPIO 27
    • Button 3 (Green): GPIO 28
    • Button 4 (Yellow): GPIO 29
  • OLED I2C:
    • SDA: GPIO 7
    • SCL: GPIO 6
    • Address: 0x3C

PCB Design

The project includes a custom PCB design with all components integrated:

Schematic

The complete schematic shows all component connections and power distribution.

Schematic

PCB Layout

The custom PCB integrates all components in a compact form factor suitable for handheld gaming.

PCB Top

PCB Bottom

3D Case Design

Custom 3D-printable case designs are available:

3D Case Top

3D Case Bottom

Software Requirements

For C++ Version

  • Arduino IDE
  • Libraries:
    • Adafruit_SSD1306 (OLED display)
    • Adafruit_GFX (Graphics library)
    • Adafruit_NeoPixel (LED control)
    • ArduinoJson (JSON parsing)
    • SPIFFS (File system - built-in for ESP32)

For Python Version (MicroPython)

  • MicroPython firmware for XIAO RP2040
  • Libraries (install via mip or copy to device):
    • adafruit_ssd1306
    • adafruit_framebuf
    • neopixel (built-in)

Installation

C++ Version

  1. Install Arduino IDE and add the XIAO RP2040 board support:

    • Go to File > Preferences > Additional Board Manager URLsr URLs
    • Add: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
    • Go to Tools > Board > Boards Manageranager
    • Search for "Raspberry Pi Pico/RP2040" and install
  2. Install Required Libraries:

    • Go to Sketch > Include Library > Manage Librariesraries
    • Install:
      • Adafruit SSD1306
      • Adafruit GFX Library
      • Adafruit NeoPixel
      • ArduinoJson
  3. Upload Code:

    • Open Code/code.cpp in Arduino IDE
    • Select board: Seeed XIAO RP2040
    • Select port
    • Click Upload
  4. Initialize SPIFFS (for score storage):

    • Use a SPIFFS uploader tool or format SPIFFS partition
    • Scores will be saved automatically on first run

Python Version

  1. Flash MicroPython:

    • Download MicroPython firmware from micropython.org
    • Hold BOOTSEL button on XIAO RP2040
    • Connect to computer via USB
    • Copy .uf2 file to mounted drive
  2. Install Libraries:

    # Connect via serial/REPL and run:
    
    import mip
    
    mip.install("adafruit-ssd1306")
  3. Upload Code:

    • Copy Code/code.py to the XIAO RP2040 as main.py
    • The device will run automatically on boot

Gameplay

How to Play

  1. Watch the Sequence: LEDs will light up in a specific order
  2. Repeat the Sequence: Press the buttons in the same order
  3. Advance Levels: Each level adds more colors to remember
  4. Beat the Timer: Complete the sequence before time runs out (in normal mode)
  5. Track Progress: Your scores are automatically saved

Game Modes

Normal Game Mode

  • Sequence shown once
  • Timer decreases each level
  • Scores tracked and saved
  • Personal best tracking

Practice Mode

  • Sequence shown 3 times
  • No timer pressure
  • Perfect for learning
  • Scores not saved

Controls

Button Function Color
B1 Up / Red 🔴 Red
B2 Down / Blue 🔵 Blue
B3 Select / Green 🟢 Green
B4 Back / Yellow / Pause 🟡 Yellow

Menu Navigation

  • B1 (UP): Navigate menu up
  • B2 (DOWN): Navigate menu down
  • B3 (SELECT): Select menu item / Confirm
  • B4 (BACK): Go back / Cancel

During Gameplay

  • B1-B4: Press corresponding colored button
  • B4 (Hold): Pause game
  • B3 (in pause): Resume game
  • B4 (in pause): Quit to menu

After Game Over

  • B3: Quick restart (within 3 seconds)
  • B4: Return to menu
  • Any button: Continue after 3 seconds

Difficulty Levels

Difficulty Start Time Time Decrease Sequence Increment Description
Easy 6.0s 0.15s/level +1 color Gentle learning curve
Normal 5.0s 0.3s/level +1 color Balanced challenge
Hard 4.0s 0.45s/level +2 colors Fast-paced action
Extreme 3.0s 0.6s/level +3 colors Maximum difficulty

Difficulty Mechanics

  • Start Time: Initial time limit per level
  • Time Decrease: How much time reduces each level (minimum 1.0s)
  • Sequence Increment: How many new colors added per level

Project Structure

Hassan-Hackpad/
├── Code/
│   ├── code.cpp          # Arduino C++ implementation
│   └── code.py           # MicroPython implementation
├── Images/
│   ├── Schematic.png
│   ├── PCB 3D Top View.png
│   ├── PCB 3D Bottom View.png
│   ├── PCB Routing.png
│   ├── 3D Case Top.png
│   └── 3D Case Bottom.png
├── HackpadPCB/           # KiCad PCB design files
├── 3D/                   # 3D component models
├── 3D case/              # 3D printable case files
└── Footprint/            # KiCad footprints and symbols
s and symbols

Code Implementation

Key Features

Score Management

  • Top 5 scores saved per difficulty
  • JSON-based storage (SPIFFS for C++, file system for Python)
  • Automatic sorting and ranking
  • Personal best tracking

Statistics Tracking

  • Total games played
  • Average scores (overall and per difficulty)
  • Games played per difficulty
  • Persistent storage across power cycles

LED Animations

  • Rainbow Cycle: Smooth color transitions
  • Success Celebration: Multi-color flash on level completion
  • Visual Feedback: LEDs light up when buttons pressed
  • Error Indication: Red flash on wrong button press

Display System

  • 3-line text display on 128x32 OLED
  • Menu navigation with visual feedback
  • Real-time timer display
  • Game over screens with statistics

Code Structure

C++ Version (Code/code.cpp)

  • Hardware Configuration: Pin definitions and constants
  • LED Functions: Control and animation
  • Display Functions: OLED text rendering
  • File I/O: SPIFFS-based score/stats storage
  • Button Input: Debounced button reading
  • UI Functions: Menus, screens, navigation
  • Game Logic: Main game loop and mechanics

Python Version (Code/code.py)

  • Similar structure to C++ version
  • Uses MicroPython libraries
  • File-based storage instead of SPIFFS
  • Pythonic implementation with dictionaries

Troubleshooting

Common Issues

LEDs Not Working

  • Check wiring to GPIO 3
  • Verify power supply (NeoPixels need 5V)
  • Check brightness setting in code
  • Ensure correct data pin connection

OLED Display Blank

  • Verify I2C connections (SDA/SCL)
  • Check I2C address (should be 0x3C)
  • Ensure proper power supply
  • Try different I2C pins if needed

Buttons Not Responding

  • Check pull-up resistors (or internal pull-ups)
  • Verify button wiring (pressed = LOW)
  • Check debounce timing
  • Test buttons individually

Scores Not Saving

  • C++: Ensure SPIFFS is initialized
  • Python: Check file system permissions
  • Verify JSON file format
  • Check available flash memory

Game Freezing

  • Check for infinite loops in button handling
  • Verify timer calculations
  • Ensure proper delay() usage
  • Check memory usage

Performance Optimization

  • C++: Optimized for XIAO RP2040 (dual-core, 264KB RAM)
  • Python: Uses efficient MicroPython implementation
  • LED Updates: Batched updates to reduce flicker
  • Display: Frame buffer for smooth rendering

License

This project is created by Hassan Mohamed. All rights reserved.

Credits

Developer: Hassan Mohamed

Project: Hassan's Hackpad - Memory Game

Hardware: Custom PCB design with Seeed Studio XIAO RP2040 / Raspberry Pi Pico

Libraries Used:

  • Adafruit SSD1306 (OLED display)
  • Adafruit GFX (Graphics)
  • Adafruit NeoPixel (LED control)
  • ArduinoJson (JSON parsing)

Support

For issues, questions, or contributions:

  • Check the troubleshooting section
  • Review code comments
  • Verify hardware connections
  • Test with practice mode first

Enjoy playing Hassan's Hackpad! 🎮✨

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published