Pololu Maestro User Manual
Page 61

0 get_position 500 less_than
return
# This subroutine uses the BUTTON subroutine above to wait for a button press,
# including a small delay to eliminate noise or bounces on the input.
sub wait_for_button_press
wait_for_button_open_10ms
wait_for_button_closed_10ms
return
# Wait for the button to be NOT pressed for at least 10 ms.
sub wait_for_button_open_10ms
get_ms # put the current time on the stack
begin
# reset the time on the stack if it is pressed
button
if
drop get_ms
else
get_ms over minus 10 greater_than
if drop return endif
endif
repeat
# Wait for the button to be pressed for at least 10 ms.
sub wait_for_button_closed_10ms
get_ms
begin
# reset the time on the stack if it is not pressed
button
if
get_ms over minus 10 greater_than
if drop return endif
else
drop get_ms
endif
repeat
# An example of how to use wait_for_button_press is shown below:
# Uses WAIT_FOR_BUTTON_PRESS to allow a user to step through
# a sequence of positions on servo 1.
main_loop:
begin
4000 frame
5000 frame
6000 frame
7000 frame
8000 frame
repeat
sub frame
wait_for_button_press
1 servo
return
Just like the sequencing examples above, the script steps through a sequence of frames, but instead of a timed delay
between frames, this example waits for a button press. The WAIT_FOR_BUTTON_PRESS subroutine can be used
in a variety of different scripts, whenever you want to wait for a button press. You could also expand this example to
allow multiple buttons, continuous motion, or a variety of other types of button control.
Using multiple buttons or switches to control servos
This script demonstrates how to connect your Maestro to multiple buttons. When a button is pressed, it runs the
corresponding sequence.
# When the script is not doing anything else,
# this loop will listen for button presses. When a button
# is pressed it runs the corresponding sequence.
begin
button_a if sequence_a endif
button_b if sequence_b endif
Pololu Maestro Servo Controller User's Guide
© 2001–2014 Pololu Corporation
6. The Maestro Scripting Language
Page 61 of 73