Start random sequence with button

Hello there, i getting more and more frustrated.

all i want is that the maestro starts any of lets say 5 sequences randomly or in order if i push a button once. So start any sequence and stop if finsh and wait for next push of the button.

  1. if i do 2 sequences and send all sequences to skript, run sequence it is starting first seq. than stop with failure overflow.

  2. i dont know how to get the buttons commands right. chat gpt for helping me is always telling commands maestro dont know.

# Include a loop to wait for the button press
begin
  begin
    button wait_for_button
  repeat

  # Once the button is pressed, start the sequence
  500 7882 0 0 0 0 frame_1..5 # Frame 0
  500 4653 frame_1 # Frame 1
  500 7549 frame_1 # Frame 2
  500 4927 frame_1 # Frame 3
repeat

sub frame_1..5
  5 servo
  4 servo
  3 servo
  2 servo
  1 servo
  delay
  return

sub frame_1
  1 servo
  delay
  return
 

this for exemple.

got this so far so good. button works and sequence work. now how to tell the programm to run for example another sequence if pushing the same button again?

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
wait_for_button_press
  500 4183 0 0 0 0 frame_1..5 # Frame 0
  500 7588 frame_1 # Frame 1
  500 4770 frame_1 # Frame 2
  500 7549 frame_1 # Frame 3
  500 4222 frame_1 # Frame 4
  500 7354 frame_1 # Frame 5
  repeat



sub Sequence_0
  wait_for_button_press
  1 servo
  return

Hello.

What you have right now looks like a good start, but the script you posted looks incomplete (i.e. it calls subroutines named frame_1..5 and frame_1, but you did not include their definition). Could you post a copy of your Maestro settings file, which will give me a more complete idea of what you’re doing? You can save a copy of your settings file from the “File” drop-down menu of the Maestro Control Center while the controller is connected.

Brandon

Test.txt (3.9 KB)

is this right? i dont think so. :thinking:

My goal is to address as many, maybe 5 sequences as possible with just one button. If possible, in a fixed order.
So, button is pressed but not held, sequence 1 runs, after the end button is pressed, sequence 2 runs, etc.

thx for your help Brandon

Hello.

It looks like you only have one sequence right now. If you want the Maestro to wait for a button press before each frame of your sequence, you can call wait_for_button_press in between each frame in your main loop, like this:

main_loop:

begin
  wait_for_button_press
  500 4183 0 0 0 0 frame_1..5 # Frame 0

  wait_for_button_press
  500 7588 frame_1 # Frame 1

  wait_for_button_press
  500 4770 frame_1 # Frame 2

  wait_for_button_press
  500 7549 frame_1 # Frame 3

  wait_for_button_press
  500 4222 frame_1 # Frame 4

  wait_for_button_press
  500 7354 frame_1 # Frame 5
repeat

Otherwise, if you just haven’t created the other sequences yet in the Sequence tab, I suggest doing that first. Then you can delete everything after your main loop in your script and use the “Copy all Sequences to Script” button in the Sequence tab, which will generate subroutines for each sequence. At that point you can rewrite your mail loop to call the sequence subroutines like this:

main_loop:

begin
  wait_for_button_press
  Sequence_0

  wait_for_button_press
  Sequence_1

  wait_for_button_press
  Sequence_2

  wait_for_button_press
  Sequence_3

  wait_for_button_press
  Sequence_4
repeat

If you try either of those and have problems getting it to work, please post an updated settings file and a description of what it’s doing wrong and I would be happy to take a look.

Brandon

ok, super, makes sense so far. here is my setup.

maestro_settings.txt (5.4 KB)

i belive it looks like you wanted it, but runs into error overflow.

It looks like you are putting the wait_for_button_press calls before the subroutine definitions, instead of within a BEGIN/REPEAT loop. To clarify, your main BEGIN/REPEAT loop should go between the main_loop: tag and the ### Sequence subroutines: ### comment, like this.

main_loop:

  begin
  
    #your wait_for_button_press code goes here

  repeat

### Sequence subroutines: ###

Brandon