Few of us have any reason to use them outside of a couple of specific board games, but hourglasses are still really cool décor. Then can be purchased for a Hamilton at your local big box store or for hundreds of dollars from some artisan practicing ancient glassblowing techniques. Ty and Gig wanted something a little more custom and built this awesome digital hourglass with the sand replaced by LEDs.
This digital hourglass works exactly like a traditional analog hourglass, with LEDs that fall down to count the passing time. The LED animations even react to the orientation of the frame, so tilting the digital hourglass to one side will cause the “sand” to collect in a corner of the bottom basin. The design is fairly minimalist with only a handful of LEDs, so those effects are more abstract than realistic, but they’re still really satisfying to watch. Those animations are also even more interesting when you understand how Ty and Gig programmed them.
The sand is displayed across a strip of WS2812B individually-addressable RGB LEDs that weave up and down the frame that was made from custom-cut wood. The LEDs are controlled by an Arduino Mega board, though Ty and Gig say that the project would have benefited from that better performance of an ESP8266. An MMA8451 accelerometer module is used to detect the orientation of the frame. That determines which direction is down and effects the falling sand animation.
That animation is what makes this project particularly cool, because it was programmed in a clever way. Instead of actually simulating physics, Ty and Gig setup a handful of structure arrays in the Arduino code. Each of those describes where the sand would fall in each orientation. That would have been impractical if this had a high-resolution display, but it works well given the limited number of LEDs used here. When the hourglass frame is tilted, the array corresponding to that orientation is selected. When a grain of sand falls, it fills in the next open position in the selected array. This looks remarkably good and is an ingenious way to get around programming physics.