Coding for Viewer Interaction

BlocklyProp made programming this artwork very easy. You may download the True Colors.svg file for BlocklyProp Solo, and I explain my approach below.

True Colors Artwork.svg

I decided to have four different servo configurations based on the viewer's position. I divided the LaserPING sensor's detection range into four zones: Far, Middle, and Near, along with a Home zone for when no viewer is detected.  I made a 6-element array for each zone, to hold the rotation angle for each of the 6 servos. 

By default, the Servo PIN block will move the standard servo quite rapidly to the angle desired. I wanted a slower transition from one canvas panel arrangement to the next.  Here's a pro tip: once you've made contact with a Standard servo using the Servo PIN block, you can use the CER servo PIN set ramp step block to slow down its movement from one angle setting to another.   So, to initialize the servos, I ran the Home function (we will look at those functions in a bit) and I set the ramp step for each servo to 8, much slower than the default.

The main code is an endless loop that simply measures the distance to the nearest object in the LaserPING sensor's range, if any, and stores that value in the distance variable.  Then, If...elseif....else compares distance to four zones   Then, the code jumps to a corresponding function, which simply sets the servo angles using the values in the matching array.  

Here is the HomeFunction code block, which uses the elements from the Home array to set the servos' angles. In this configuration, the canvas panels are mostly lined up straight to hide all the bright colors.

There are nearly identical blocks named FarFunction, MiddleFunction, and NearFunction, which use their namesake arrays to set their own canvas panel configurations.  The Far array values move just two servos slightly away from their Home positions, the Middle array moves two more, and the Near array has the canvas panels all rotating to expose the bright colors underneath.

Of course, this application is not much of a challenge for the Propeller Activity Board WX. I am considering adding sound next, so the viewer has something to hear as well as something to see. Stay tuned!