กลับไปหน้ารวมไฟล์
esp8266-animated-hourglass-oled-en.md

Gravity Simulation: Animated OLED Hourglass

The Animated Hourglass is an incredibly satisfying visual project. Instead of just displaying text, the display renders dozens of individual "sand particles" (pixels). As you tilt the breadboard physically, the particles actually "fall" according to the laws of digital gravity!

stock_counter_lcd_setup_1772706693516.png

The Matrix Mathematics

The ESP8266 is vital for this project due to its processing speed.

  • The Sensors: An MPU6050 Accelerometer constantly reads the tilt of your board on the X and Y axes.
  • The Draw Loop: The code creates an array representing every sand particle. In every loop frame, it calculates:
    1. Which way is down? (from the MPU6050 reading).
    2. Is there an empty pixel below the sand particle?
    3. If yes, erase the current pixel and draw it one pixel lower.
  • The Adafruit_GFX library pushes these massive frame updates to the 0.96" OLED Display at an incredibly fast frame-rate.

Core Hardware Setup

  • ESP8266 NodeMCU or ESP32: Required for high-speed calculation to achieve smooth animation.
  • MPU6050 6-Axis IMU Module.
  • 0.96" I2C OLED Screen.
  • Mini Breadboard.

By adding collision detection (drawing an hourglass shape outline that the sand cannot pass through unless it hits the narrow "choke point" in the middle), you create a stunningly realistic physics simulation in just 500 lines of code.

ข้อมูล Frontmatter ดั้งเดิม

title: "DIY ESP8266 Animated Hourglass"
description: "Tilt to run! Program an OLED screen to simulate a gravity-driven hourglass, using an IMU to update pixel positions dynamically."
category: "Games & Toys"
difficulty: "Advanced"