Animated Sand demo
Project started 2/2/2019
Written by Larry Bank
[email protected]
Based on Phil Burgess' Animated Sand code
The purpose of this code is simulate grains of sand on a 2 dimensional surface. An accelerometer provides the tilt sensing to give motion to the grains. My purpose in writing this was to understand the logic of such a physics demo and to optimize it. Starting from Phil's code, I made the following changes:
- Switched to a different accelerometer (MPU-6050 - what I had on hand)
- Upgraded display from a 15x7 LED matrix to a 128x64 monochrome OLED (SSD1306)
- Increased the number of grains from 20 to 250
- Image matrix from 1 byte per pixel to 1 bit per pixel to match the display
- Image memory mapping to match the memory layout of the display for easy updating
- Simplified the pixel 'bounce' loop by removing some calls to abs() and simplifying other code
- Removed the floating point math in the 2D vector limiting code
- Added oledDumpBuffer() function to my oled_96 library which only transmits blocks of 16x8 pixels which have changed since the last call (aka dirty rectangle - for speed)
- Fixed bug in collision logic which allowed grains to overlap
This code depends on my oled_96 library. You can download it here:
https://github.com/bitbank2/oled_96
If you find this code useful, please consider buying me a cup of coffee