WS2811 "Water torture"

From Just in Time

Revision as of 00:14, 8 November 2019 by Danny (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Quickie project based on the 8MHz WS2811 driver

The source code is part of the driver demonstration sources. This particular demo is in water_torture.hpp.

The code is in C++ and uses a class, "droplet" to maintain the state of the droplets that are animated on the LED string. At most 2 droplets are animated at the same time and when droplets overlap, their colors are mixed.

Each droplet can be in one of four states, which are traversed in order:

the droplet does nothing and is not visible.
the droplet stays at the top of the led string and slowly increases in intensity, until it reaches a randomly chosen intensity.
the droplet falls downwards and accelerates. This state ends when the droplet passes the bottom position.
the droplet has bounced of the ground. A smaller, less intensive droplet bounces up while a part remains on the ground. The droplet moves upwards, decelerates and falls down again. After hitting the ground while in the bouncing state, the droplet returns to the inactive state.

The droplet animation is smooth because positions are maintained in 8.8 fixed point, meaning that there are 256 positions between two adjacent LEDs. When a droplet is is positioned between two leds, its intensity is divided over the two leds.