Long delays – Pololu Maestro User Manual
Page 62

button_c if sequence_c endif
repeat
# These subroutines each return 1 if the corresponding
# button is pressed, and return 0 otherwise.
# Currently button_a is assigned to channel 0,
# button_b is assigned to channel 1, and
# button_c is assigned to channel 2.
# These channels must be configured as Inputs in the
# Channel Settings tab.
sub button_a
0 get_position 500 less_than
return
sub button_b
1 get_position 500 less_than
return
sub button_c
2 get_position 500 less_than
return
# These subroutines each perform an arbitrary sequence
# of servo movements. You should change these to fit
# your application.
sub sequence_a
4000 3 servo 1000 delay
6000 3 servo 500 delay
return
sub sequence_b
8000 4 servo 900 delay
7000 4 servo 900 delay
6000 4 servo 900 delay
return
sub sequence_c
10 4 speed
7000 4 servo 3000 delay
6000 4 servo 3000 delay
return
Please note that this script does not do multi-tasking. If a sequence is running, the script will not detect other button
presses until the sequence is done. It is possible to make the buttons operate independently, but the script would need
to be much more complicated. Depending on how skilled you are at writing scripts, you might prefer to use multiple
Maestros instead.
Long delays
The longest delay possible with the DELAY command is approximately 32 seconds. In some cases, you will want to
make delays much longer than that. Here is an example that shows how delays of many seconds or minutes can be
accomplished:
# Moves servo 0 back and forth, with a delay of 10 minutes between motions.
begin
4000 0 servo
10 delay_minutes
8000 0 servo
10 delay_minutes
repeat
# delay by a specified number of seconds, up to 65535 s
sub delay_seconds
begin dup while # check if the count has reached zero
1 minus 1000 delay # subtract one and delay 1s
repeat
drop return # remove the 0 from the stack and return
# delay by a specified number of minutes, up to 65535 min
sub delay_minutes
begin dup while
1 minus 60 delay_seconds # subtract one and delay 1min
Pololu Maestro Servo Controller User's Guide
© 2001–2014 Pololu Corporation
6. The Maestro Scripting Language
Page 62 of 73