Switch for sequence

Hello, I am new here and searched everywhere for the answer to my question. I just bought a Maestro 6ch USB controller for a Power 1810MG for my project.
I have the board controlling my servo (Ch.0) and the simple 3 frame sequence is complete.
I have a simple pushbutton switch (Ch.1) that I want to use to simply play the sequence each and any time the button is pushed.
I changed the mode on Ch1 to Input and will wire the switch as shown on the diagrams.

Question, where do I/how do I program the switch on Ch1 to play the sequence?

Many many thanks,
Paul

To preface this I do not know exactly how the maestro works…

This is the how you would start doing what you ask.

You would just need to set up a function that, when called, runs your sequence. To call it, you set up an interrupt on that pin.

Hello, Paul.

The Software Development Kit is probably much more than you need for your project. You should be able to accomplish what you described with a Maestro script. You can find our “Using a button or switch to control servos” example in the “Example Scripts” section of our “Maestro Servo Controller User’s Guide”, which is a good place to start for a project like you outlined. You can find that user’s guide (and other resources), under the “Resources” tab of the Maestro’s product page.

If you get started and have problems, you can post what code you have so far here, and we would be glad to offer some suggestions.

-Derrill

I had some help getting the servo to do what I wanted to do on another friend’s computer. It was working with my button.
Now I get home to try to make some adjustments but when I paste the former script into Maestro, the script seems to always run and gets stuck and I can never save the settings. Hence, now my switch is not working. Here is the script:

goto main_loop
 
# 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
 
# Uses WAIT_FOR_BUTTON_PRESS to allow a user to step through
# a sequence of positions on servo 1.
main_loop:
begin
  frame
repeat
 
sub frame
  wait_for_button_press

  # DELAY POSITION FUNCTION
  500 3968 move90
  500 6000 moveOriginal
  
  return

sub move90
  1 servo
  delay
  return

sub moveOriginal
  1 servo
  delay
  return

Can you post your settings file? You can save settings file for your Maestro using the “Save settings file…” option under the “File” menu of the Maestro Control Center software. When you press the button, do you see the slider in the “Status” tab of the Maestro Control Center reacting as you expect?

-Derrill

Ok, so there was a glitch on my end and it is working again. Thank you. But here is something I notice that does not make sense.

When my 6v battery supply is powering the servos (one servo) and the board is connected to the USB on my PC, the button is doing exactly what I want.
BUT
When I use my 6v battery supply to drive the board and servo, the button again does exactly what I want each time I press the button.
The issue is:
My current layout includes a Master “Power” Button that disconnects the battery supply voltage from the servo and board. If I turn off the master power button after a button push (on channel 0) to activate my servo, when I repower the servo and board, the servo rotates about 30 degrees that I don’t and can’t have. If I press my servo control button, it does what it is supposed to and returns to its normal starting point. It will do this time and time again (as I want it to) with each button press. BUT when I turn off the master power, it always powers on with the servo in that new position that I do not want.

How do we avoid this?
Thanks!

Glad to hear you got your original issue solved. Please post your settings file (as described in my last post), so I can see what your program looks like and what your channel settings are.

-Derrill

Here is what I had posted earlier with the necessary changes to accomodate the new servo I am using:[quote=“Rock, post:4, topic:16230”]
goto main_loop # 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 # Uses WAIT_FOR_BUTTON_PRESS to allow a user to step through # a sequence of positions on servo 1. main_loop: begin frame repeat sub frame wait_for_button_press # DELAY POSITION FUNCTION 500 8000 move90 500 990 moveOriginal return sub move90 1 servo delay return sub moveOriginal 1 servo delay return
[/quote]


goto main_loop
# 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
# Uses WAIT_FOR_BUTTON_PRESS to allow a user to step through
# a sequence of positions on servo 1.
main_loop:
begin
  frame
repeat
sub frame
wait_for_button_press
# DELAY POSITION FUNCTION
  500 8000 move90
  500 990
  moveOriginal
return

sub move90
  1 servo
delay
return

sub moveOriginal
1 servo
delay
return

Please post your settings file as I asked.

-Derrill

Oh man, I thought the script I posted was what you asked for. I will go back and attempt what you wrote.

Thanks

Here is the file, for some reason when I tried to copy and paste the file, there was an error and the message was truncated.

When I press the button when the controller is connected via USB, it operates as I want it to and the slider simply runs from one end to the other with each push.

maestro_settings.txt (3.2 KB)

Thank you for posting your settings file; your settings seem fine. I tested your script with a servo here and it worked as expected. I suspect your servo is the issue. Some servos have a significant twitch or move to some particular position when power cycled. You might try a different type of servo to see if that helps.

Alternatively, you might make your first command (e.g. as soon as your script starts) move that servo to the position you want it to start in. You could also do this by setting the “On startup or error” condition in the “Channel Settings” tab to “Goto”, and specifying the position to some starting position.

-Derrill