Actions

WS2811 "Water torture"

From Just in Time

Revision as of 18:38, 9 December 2014 by Danny (talk | contribs)

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:

inactive
the droplet does nothing and is not visible. This remains the case until
swelling
the droplet stays at the top of the led string and slowly increases in intensity, until it reaches a randomly chosen intensity.
falling
the droplet falls downwards and accelerates. This state ends when the droplet passes the bottom position.
bouncing
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.