An animated line bouncing demo for the Cheap Yellow Display (CYD) ESP32-2432S028R. This project creates a dynamic screen saver-style animation with bouncing lines that leave colorful trails.
This Arduino sketch animates a line with two endpoints that bounce around the screen, leaving a gradient trail behind it. The animation features:
- Bouncing Physics: Lines bounce off screen boundaries with randomized velocities
- Trail Effect: Smooth gradient trail that fades from blood red to candy apple red
- High Performance: Runs at maximum frame rate with no artificial delays
- Dynamic Movement: Random starting positions and velocity changes on bounces
📺 Watch it in action: CYD Line Bounce Demo
- Display: Cheap Yellow Display (CYD) ESP32-2432S028R
- Resolution: 320x240 pixels
- Interface: SPI TFT display
- Microcontroller: ESP32
- 5 Trail Lines: Smooth interpolation between stored positions
- Gradient Colors: Blood red to candy apple red gradient
- Smooth Movement: All trail lines move fluidly with the main line
- Configurable Spacing: Adjustable trail spacing via
TRAIL_SPACING
- Random Bounces: Velocity changes randomly on boundary collisions
- Speed Range: Configurable minimum/maximum velocities
- Boundary Detection: Proper collision detection and position correction
- No Sticking: Robust edge handling prevents lines from getting stuck
#define TRAIL_LENGTH 5 // Number of trail lines
#define TRAIL_SPACING 3 // Frames between trail position updates
#define VELOCITY_MIN 5 // Minimum bounce velocity
#define VELOCITY_MAX 12 // Maximum bounce velocity
#define FRAME_DELAY 0 // Frame delay (0 = maximum speed)The trail colors can be easily modified in the trailColors array:
uint16_t trailColors[TRAIL_LENGTH] = {
0x6000, // Blood red - back trail line
0xCA0A, //
0xFB0F, //
0xE004, //
0xF840 // Candy apple red - front trail line
};- Install Libraries: Ensure TFT_eSPI library is installed with the correct User_Setup.h file. I followed this to get my CYD running the first time with Arduino: https://randomnerdtutorials.com/cheap-yellow-display-esp32-2432s028r/
- Configure TFT_eSPI: Set up the library & display settings in CYD_line_bounce.ino for your specific display
- Upload Code: Compile and upload to your ESP32
- Enjoy: Watch the bouncing lines...straight from the 1980's
- Uses circular buffer to store trail positions
- Interpolates between stored positions for smooth movement
- Updates trail positions every
TRAIL_SPACINGframes - Handles frame counter overflow protection
- Runs at maximum hardware speed (no artificial delays)
Modify the trailColors array to create different gradient effects:
- Use RGB565 color format
- Create custom gradients from any color to any color
- Experiment with different color combinations
- Increase Speed: Raise
VELOCITY_MAX - Decrease Speed: Lower
VELOCITY_MIN - Change Trail Density: Modify
TRAIL_SPACING
- The 5th trail line (closest to main line) is currently disabled due to visual inconsistencies
- Some color combinations may not display correctly depending on display configuration
- High speeds may cause occasional visual artifacts
This project was created as a vibe coding experiment with Cursor AI. The code is functional but not optimized for production use. It serves as a rough starting point for TFT display animations and can be extended with additional features.
Feel free to fork this project and experiment with:
- Different trail effects
- Multiple bouncing lines
- Interactive controls
- Sound effects
- Network connectivity features
Created for the Cheap Yellow Display community - enjoy your bouncing lines! 🎯
