Asteroid Smash is a real-time arcade-style game developed on the ESP32 microcontroller to explore and learn FreeRTOS. The player pilots a spacecraft using an IMU (Inertial Measurement Unit), dodging and shooting incoming asteroids. The game features an OLED display for visuals and a piezo buzzer for sound effects, delivering a retro gaming experience on embedded hardware.
- Learn and apply FreeRTOS concepts: tasks, queues, semaphores, and timers.
- Interface with multiple peripherals: IMU, OLED, and piezo buzzer.
- Implement real-time game logic with responsive controls and dynamic rendering.
- ESP32 Dev Board
- OLED Display (SSD1306 or SH1106, I2C)
- IMU Sensor (e.g., MPU6050 or similar)
- Piezo Buzzer
- Optional: Push buttons for reset or fire control
- IMU-based spacecraft control: Tilt to steer, dodge, and aim.
- Asteroid generation and movement: Randomized spawn and trajectory.
- Projectile system: Fire bullets to destroy asteroids.
- Collision detection: Real-time hit and dodge logic.
- Sound effects: Piezo buzzer feedback for shooting and collisions.
- Multitasking architecture: Game loop, input handling, rendering, and sound run as separate FreeRTOS tasks.
| Component | FreeRTOS Feature |
|---|---|
| Game Loop | Periodic Task |
| IMU Input | Task + Queue |
| OLED Rendering | Task + Mutex |
| Sound Effects | Task + Timer |
| Collision Logic | Shared Resource Access |
-
Clone the repository
git clone https://github.com/yourusername/asteroid-smash-esp32.git
-
Install dependencies
- ESP-IDF or Arduino framework
- FreeRTOS (included in ESP-IDF)
- Adafruit SSD1306 / U8g2 library (for OLED)
- MPU6050 or IMU library
-
Connect hardware
- Wire up OLED to I2C pins
- Connect IMU to I2C
- Attach piezo buzzer to a PWM-capable GPIO
-
Build and flash
idf.py build idf.py flash
- Tilt Left/Right: Steer spacecraft
- Tilt Forward: Accelerate
- Button Press (optional): Fire projectile
(Add photos or gifs of gameplay on OLED screen here)
- Add score tracking and high-score memory
- Implement power-ups and enemy ships
- Improve graphics with sprite animation
- Add menu and pause functionality
This project helped me:
- Understand task scheduling and synchronization in FreeRTOS
- Interface multiple peripherals in real-time
- Design a modular embedded game architecture
- Explore sensor fusion and motion control
MIT License. Feel free to fork, modify, and build upon it!