36 March 2014
generator is seeded, the wire library is
initialized, and the IRremote library is
enabled for reception of IR signals. A
check is then made to be sure the RTC
is running, then the Arduino’s
EEPROM is initialized for storage of
the clock’s color configuration
information. Finally, all of the RGB
LEDs are turned off until needed.
The loop() function is a lot more
complex. In essence, it runs a series of
state machines that control the
operation of the clock. I chose a state
machine implementation because it
makes the code easier to read and
maintain than if it were coded with
massively nested if-then-else structures.
In a state machine, transitions
between states occur when specific
stimulus is applied while in a current
state that is expecting it. All extraneous
inputs are ignored. The input stimulus
(in our case) results from keys being
pressed on the remote control.
A good example of state machine
operation can be seen in the function
hsvColorSetter in the sketch. Here,
clicking keys on the remote control
causes the state machine to move
back and forth between two states
while the user configures a color for
use in the clock. Clicking the
STOP/MODE or the ENTER/SAVE keys
on the remote causes the state
machine to exit with the definition of
the HSV color the user was setting.
HSV (or Hue, Saturation, and
Value) color values are used
extensively in the clock’s code. Each of
these color attributes can be
manipulated independently and have
different effects. Hue is the actual
degrees between 0 and 359. A hue of
zero is red, a hue of 120 degrees is
green, and a hue of 240 is blue. Hues
in between these values are a mix of
the surrounding colors.
Saturation determines how pure a
color is and has values between 0.0
and 1.0. Fully saturated colors are
deep and full, while lesser saturated
colors trend towards pastels and white.
Value determines the brightness of
the color and also ranges in value from
0.0 to 1.0. The higher the value, the
brighter the color. As an example, a
hue value of 0.0, a saturation value of
0.0, and a value of 1.0 results in the
Inside the loop() function, the
current time and date is read every
second from the RTC and displayed on
the LEDs if the clock is in clock mode.
Other things happen in the other
operational modes of the clock. See
the discussion of the Remote Control
for more info.
Reading the Time
I packaged my clock in a rather
unique vertical format, so it takes a
little time to get comfortable reading it.
While displaying the time, all of the
LEDs are first set to the background
color (default blue), then the hour
value is displayed (default red) with the
top LED indicating 12 o’clock and
counting down towards 1 o’clock at
Since minutes are displayed on the
same scale, they are only available
with five minute resolution. To
determine the minutes count, count
up by fives from the bottom LED. For
example, if the fifth LED from the
bottom is lit (minutes are displayed in
green by default), the minute count is
between 25 and 30.
How often do you need the exact
minute count? Not often, so a five
minute resolution was deemed
sufficient. Since hours and minutes are
■ PHOTO 3. Here, you can see
the RGB LEDs through square
holes cut into the 1" PVC pipe.
The PVC pipe was press-fit into a
1" hole drilled through the top two
acrylic discs and painted with a
dark gray sparkle paint.