Sequence in button press script not working

Hello,

NOOB here, go easy on me!

Using Pololu Maestro micro 6 and referring to manual section 6.c Sample Scripts I can easily copy and paste in the “Using a button or switch to control servos” script. Works perfectly.

NOW, I need to integrate a sequence I created by capturing frames and adjusting durations in the Maestro Control Center’s “Sequence” tab. Simple, but I’m screwing it up!

Can anybody see the simple mistake I have in this script that is attempting to run the sequence once upon button push? TIA!

Here it is:

goto main_loop    # Run the main loop when the script starts (see below).
 
# This subroutine returns 1 if the button is pressed, 0 otherwise.
# To convert the input value (0-1023) to a digital value (0 or 1) representing
# the state of the button, we make a comparison to an arbitrary threshold (500).
# This subroutine puts a logical value of 1 or a 0 on the stack, depending
# on whether the button is pressed or not.
sub button
  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

#not sure how to put in my "Sequence_0" here

repeat

sub Sequence_0
  wait_for_button_press
  1 servo
  return




#mystuff



# Sequence_0
begin
  500 0 6000 0 0 0 frame_0..4 # Frame 0
  500 3982 frame_1 # Frame 1
  500 7970 frame_1 # Frame 2
  500 7384 frame_1 # Frame 3
  500 6240 frame_1 # Frame 4
  500 5067 frame_1 # Frame 5
  500 3968 frame_1 # Frame 6
  500 5918 frame_1 # Frame 7
repeat


sub frame_0..4
  4 servo
  3 servo
  2 servo
  1 servo
  0 servo
  delay
  return

sub frame_1
  1 servo
  delay
  return

Hello.

I added code tags to your code to make it easier to read. Please format your code in future posts by putting a backtick (`) before and after the code or indenting the code by four spaces.

Looking at your script, I think the easiest (and least confusing) way for you to combine the “Using a button or switch to control servos” script example with your auto-generated script is to remove the begin/repeat block and Sequence_0 subroutine under the main_loop label and call the wait_for_button_press subroutine before executing your movement sequence like so:

main_loop:
begin
  wait_for_button_press		  # call subroutine before executing sequence
  500 0 6000 0 0 0 frame_0..4 # Frame 0
  500 3982 frame_1 # Frame 1
  500 7970 frame_1 # Frame 2
  500 7384 frame_1 # Frame 3
  500 6240 frame_1 # Frame 4
  500 5067 frame_1 # Frame 5
  500 3968 frame_1 # Frame 6
  500 5918 frame_1 # Frame 7
repeat

- Amanda

Hi Amanda,

Thank you for cleaning up the code. I will add tags in the future.

I change the script (only the part you corrected) and we still have a no-go. It does not report any errors, but still does not work.

Ideas?

I appreciate the help!

WAIT! It works! Stupid me had the button address wrong.

Thank you very much!

I’m glad the change worked for you; thanks for letting me know.

- Amanda