ColorPAL documentation

© Parallax, Inc. • ColorPAL (2009.06.15) Page 10 of 12
The ColorPAL normally references the full-scale output of the light sensor to +5V. For very low-light
situations, this output can be referenced to 1.1V instead, which effectively multiplies the sensitivity by
more than 4.5. This setting is not recommended for normal ambient lighting conditions or cases where
the internal LED is used to illuminate a subject. This is because the reading will saturate just from the
ambient light or reflections from the plastic snorkel. But for low-ambient conditions with external color
illumination, the high sensitivity setting may well be useful. As a complement, the low sensitivity
command can be used to return to the default setting.
In the following example, a sample is taken at high sensitivity, returning to low sensitivity when finished:
SEROUT sio, baud, ["= h s l!"]
SERIN sio, baud, [HEX3 Value]
— Program Flow and Miscellaneous Commands —
pnn
Pause
The pause command takes a two-hex-digit argument and pauses execution for time approximately equal
to nn · 5ms. Here’s an example that displays yellow, cyan, and magenta each for one second, then
fades to black:
SEROUT sio, baud, ["= Y pC8 C pC8 M pC8 t50 X !"]
(nn
Begin a Program Loop
)
End a Program Loop
This command pair defines a loop within a program. The “begin” command takes a two-hex-digit
argument, which tells how many times the loop is to be executed. If this amount is 00 the loop is
executed infinitely. Loops can be nested. Here’s an example that alternates between red and green ten
times, finishing with a transition to blue:
SEROUT sio, baud, ["= (0A R p64 G p64 ) t50 B !"]
>nn
Call a Subroutine in EEPROM
Programs saved with the #nn direct command can be called as subroutines from a running program. The
two-hex-digit argument (00 3F) specifies the EEPROM address of the program to call. In this example,
the program from the prior example is called as a subroutine, then its blue finale slowly fades to black:
SEROUT sio, baud, ["= (0A R p64 G p64 ) t50 B #20"]
PAUSE 100
SEROUT sio, baud, ["= >20 tFF X !"]
The PAUSE statement is in there because the micro requires some time to store the program. Without it,
the following SEROUT would occur too soon, and the ColorPAL would ignore it.
?nn
Set Random Deviation
Sometimes it’s nice to mix things up a little for certain color displays (e.g. flickering candles). The set
random deviation command (?) lets you do just that. The parameter following the question mark is kept
as the current random deviate. Once it’s been established, any subsequent parameter to the pause,
transition-time, rgb-color, and (loop) commands will be affected by randomization. It works as follows: