One of the things we learn with experience is that
paper components work perfectly — it’s when they’re
living in the real world that they can misbehave. The goal
here was to use the DMX level to drive the number of
LEDs that are on. As mentioned, I didn’t have access to
the original code, so I speculated based on reports from
the set.
NCO mode which is intended for PWM and pulse
generation. Keep in mind that each cog has its own I/O
configuration, and these get OR’d together for the
physical pins; this lets us use one cog to monitor an I/O
pin that is being controlled by another cog.
For the test, the PWM output is connected to P26.
This lets me see changes on the LED and read the output
and input values in the terminal window:
pub main | level, in
setup
It seems like the original version divided the 0..255
range into eight thresholds and used that to select how
many pixels were illuminated. The problem was on the
ends: If zero is all off and 255 is all on, a little bit of noise
in the pot on the lighting board could cause fluttering in
the output (this was reported).
repeat
repeat level from 0 to 255
pwmo.duty(0, level)
time.pause(50)
term.rjdec(level, 3, “““)
term.txn(“““, 4)
in := 256 pwmtix / MS_005
term.rjdec(in, 3, “““)
In my past, I’ve coded camera platform controls. Even
very high quality joysticks do not center to the same place
every time. In those devices, I used a dead band near the
center so that a neutral joystick would cause both axes to
stop. For this project, I used dead bands on the ends; that
way, near zero would be full off, and near 255 would be
full on.
term.tx(13)
Using 5% on either end gave me a dead band of 12
units, which means a full operational range of 232 units.
Dividing 232 by eight (pixels), we get 29. It’s not a lot, but
29 brightness steps for each pixel is better than one.
Here’s the math for calculating pixel brightness from
the DMX control inputs:
This is the loop that ramps the PWM signal output
from 0 (0%) to 255 (100%).
After setting the output, there is a short delay to
ensure that the background could measure the signal. The
captured “on” ticks are converted to 0..255 with a simple
equation. Easy peasy.
npix := (level - 12) / 29
partial := map((level - 12) // 29, 0, 28,
0, 255)
partial := partial brightness / 255
The next step was to fold the code into a standard
object that allows both counters to be used and has the
ability to measure the “high” or “low” ticks of a signal. We
can also set the sample window period. With that in
place, it was time to address the LED control for the
costume piece.
Smooth Operator
Once everything was working, Rick asked if I could
smooth out the behavior of the LEDs. In the original piece,
the eight-pixel strip would turn on one pixel at a time —
like a bar graph. It worked but there was a little jarring
when a pixel would go from full off to full on. He asked if I
could fade each pixel on instead, which he believed would
result in a smoother looking animation. Of course, he was
right.
The variable npix is the number of pixels that will be
fully lit. This is calculated by subtracting 12 (dead band)
from the control level, and then dividing by 29. The next
line does two steps in one: It uses modulo (//) to
determine the remaining steps in the last LED, then maps
those steps to a normal brightness level of 0..255. The
map() method scales an input range to an output range;
in this case, we want to expand 0.. 28 to 0..255. The final
line scales the partial brightness pixel to the brightness
control channel value.
Rick and I finalized everything in his shop on
Christmas day. Yeah, I know, working on Christmas day
seems like a drag. It wasn’t really; he’s Jewish and I don’t
have any family in Los Angeles — why not spend
Christmas with one of my best friends making cool things
in his shop?
Jon “JonnyMac” McPhalen
jon@jonmcphalen.com
The DMX receiver has four channels. The original
piece used only one. Due to the nature of the show and a
lot of nighttime action, the lighting folks asked if we could
add an overall brightness control. Yes, we can, and that’s
the variable called brightness (it’s the second value in the
DMX stream).
Parallax, Inc.
www.parallax.com
Propeller boards, chips, and programming tools
Having been around movies and TV, we know that
lighting situations can vary wildly. Knowing this and having
spare cogs, we decided to add two more PWM input
82 May/June 2018