Button problem

I’m just starting out with the maestro servo controllers and have a button issue. I can start a sequence on button push but how do suspend the script or stop it then start again on button up.
If I put wait_for_button_open_10ms as the first line under Begin this works but only after the script get back to the beginning so there is a delay suspending the script.
Where is the code tag option?

Code follows, no it doesn’t work
indent preformatted text by 4 spaces

# stab
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
  0x10 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



#main_Loop#
sub Stab_0
begin
  500 3968 0 0 0 0 0 
  0 0 0 0 0 0 
  0 0 0 0 0 frame_0..15_17 # head R
  500 7882 frame_0 # head L
  500 6000 frame_0 # head Nuteral
  500 0 4144 frame_0_1 # R shd Babk
  500 6943 frame_1 # R shd Fwd
  500 5984 frame_1 # R shd nuteral
  500 0 8000 frame_1_2 # L shd Back
  500 4065 frame_2 # L shd fwd
  500 6003 frame_2 # L shd nuteral
  500 0 4046 frame_2_3 # R shd up
  500 0 8000 frame_3_5 # st stab
  200 4046 frame_5 # sd1
  200 7628 frame_5 # su1
  200 4202 frame_5 # sd2
  200 7725 frame_5 # su2
  200 4202 frame_5 # su3
  300 5964 frame_5 # stp stab
  500 0 7745 frame_5_10 # l hip back
  500 4202 frame_10 # l hip fwd
  500 6003 frame_10 # l hip nuteral
  500 0 frame_10 # all off
repeat

main_loop:
sub Frame
  # wait_for_button_closed_10ms
   wait_for_button_open_10ms  # shouldn't this stop the script,stay in button loop while button is closed?
  # wait_for_button_press     # i guess hte question is how to exit begin-repeat then resume where I left off
   stab_0

   

sub frame_0..15_17
  17 servo
  15 servo
  14 servo
  13 servo
  12 servo
  11 servo
  10 servo
  9 servo
  8 servo
  7 servo
  6 servo
  5 servo
  4 servo
  3 servo
  2 servo
  1 servo
  0 servo
  delay
  return

sub frame_0
  0 servo
  delay
  return

sub frame_0_1
  1 servo
  0 servo
  delay
  return

sub frame_1
  1 servo
  delay
  return

sub frame_1_2
  2 servo
  1 servo
  delay
  return

sub frame_2
  2 servo
  delay
  return

sub frame_2_3
  3 servo
  2 servo
  delay
  return

sub frame_3_5
  5 servo
  3 servo
  delay
  return

sub frame_5
  5 servo
  delay
  return

sub frame_5_10
  10 servo
  5 servo
  delay
  return

sub frame_10
  10 servo
  delay
  return

I’m using the HC-05,6 & 8 all work fine. I’m not sure this is a bluetooth problem but here goes.
I send an 0xA4 the the script stops as it should. 0xA3 and 0x93 work. I can not restart with 0xA7 & routine #. All commands more than a byte cause a stack overflow as do some 1 byte commands. I tried this in Pololu terminal and the 0xa7 also failed as well some other commands. UART Setting set at fixed baud rate of 9600 both bluetooth and the terminal. Any ideas?

Thank you

Hello.

I merged both your posts into one thread to keep things organized. To see how we formatted your code to make it more readable, you can click on the pencil icon in the upper right-hand corner of your first post and view the raw source.

In your first post, it sounds like you want to be able to stop running the movement sequence at any point in the script when the button is not pressed and resume where it left off when the button is pressed. Is that correct? If so, you would need to use an interrupt, which the Maestro does not support. You might consider using a microcontroller that supports interrupts such as an Arduino or an Arduino-compatible board (like the A-Star Programmable Controllers). With the microcontroller, you can handle the button triggers and send the appropriate commands to the Maestro based on the button’s status. If you decide to use the Arduino (or A-Star), you can use the Arduino library for the Maestro to send commands to the Maestro via its serial interface. You can get a better understanding of how the library works by looking at its examples.

Regarding your second post, what subroutine number did you pass with the 0xA7 command byte to restart the script? Do you get the same error(s) if you send 0xA7 0x05? If so, can you simplify your code down to the simplest possible thing that should work, but does not and post it here? You might find the “Step Script” button in the “Script” tab of the Maestro Control Center helpful for debugging and seeing how each line of code affects the stack.

- Amanda