Digital output – Pololu Maestro User Manual
Page 63

Connecting the Micro Maestro to a chain of
ShiftBars. A single 12V supply powers all of the
devices.
repeat
drop return # remove the 0 from the stack and return
It is easy to write subroutines for delays of hours, days, weeks, or whatever you want. Keep in mind, however, that
the timer on the Micro Maestro is not as accurate as a stopwatch – these delays could easily be off by 1%.
Digital output
The digital output feature of the Maestro is capable of
controlling anything from simple circuits to intelligent
devices such as the
and
simple synchronous serial protocol. In this example, the
clock, latch, and data pins of a ShiftBrite or ShiftBar are
connected to servo channels 0, 1, and 2, respectively, and
these channels are all configured as outputs. The
subroutine RGB defined here takes 10-bit red, green, and
blue values from the stack, then sends a 32-byte color
packet and toggles the latch pin to update the ShiftBrite
with the new color value. The subroutine could be
modified to control a larger chain of ShiftBrites if desired.
begin
1023 0 0 rgb 500 delay # red
0 1023 0 rgb 500 delay # green
0 0 1023 rgb 500 delay # blue
repeat
# Subroutine for setting the RGB value of a ShiftBrite/ShiftBar.
# example usage: 1023 511 255 rgb
sub rgb
0 send_bit # this bit does not matter
0 send_bit # the "address" bit - 0 means a color command
swap rot rot
send_10_bit_value
send_10_bit_value
send_10_bit_value
0 1 8000 1 servo servo # toggle the latch pin
return
# sends a numerical value as a sequence of 10 bits
sub send_10_bit_value
512
begin
dup
while
over over bitwise_and send_bit
1 shift_right
repeat
drop drop
return
# sends a single bit
sub send_bit
if 8000 else 0 endif
2 servo # set DATA to 0 or 1
0 0 8000 0 servo servo # toggle CLOCK
return
Note that we use 0 to set the output low and 8000 to set the output high. These are reasonable choices, but any value
from 0 to 5999 could be used for low, and anything from 6000 to 32767 could be used for high, if desired.
Pololu Maestro Servo Controller User's Guide
© 2001–2014 Pololu Corporation
6. The Maestro Scripting Language
Page 63 of 73