Project Overview
The goal was to recreate a classic virtual pet using modern microcontrollers. This project implements a real-time "hunger and happiness" decay system, non-volatile storage for saving pet progress, and a dynamic UI.
- Custom interrupt-driven button debouncing.
- Optimized SPI display updates for 30FPS performance.
[device_demo.MOV]
Hardware Architecture
Microcontroller
Utilizing the ESP32-S3 for its dual-core processing and ample GPIO for peripheral expansion.
Display
4.0" ST7796S TFT display using SPI protocol with DMA for smooth sprite rendering.
Power
LiPo battery management with deep-sleep modes to maximize device longevity.
Software Implementation
pet_logic.cpp
void updatePetStats() {
// Stat decay over time using millis() tracking
if (currentMillis - previousMillis >= DECAY_INTERVAL) {
hunger -= 1;
happiness -= 0.5;
if (hunger < 10) triggerAlert(LOW_FOOD_ICON);
previousMillis = currentMillis;
}
}