Help with adding an extra servo to current Script

Good Afternoon all,

Im a complete novice when it comes to scripting. I have a working script below (press the button to open the servo, press again to close) and want to add an extra servo to do the same at the same time, problem is…I have no idea how to do it!

Im using the Mini maestro 12 channel, could anyone provide me with the code to attach extra servos to the spare ports? Im sorry it will have to be at the most basic level.

This is the current code;

[code]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
1229 frame
5000 frame

repeat

sub frame
wait_for_button_press
1 servo

return[/code]

Thank you in advance, Chris

Hello, Chris.

Thank you for including your script. To add code for a second servo that does the same thing as the first, you could first add a duplicate servo target position to the stack in your main_loop (before calling the frame subroutine each time). You could do this by copying the same values that are already there and pasting them again or by using the “DUP” command. For example, your new main_loop might looks like this:

main_loop:
begin
  1229 dup frame    #the dup command will duplicate the value that comes before it
  5000 dup frame
repeat

Once that is done, the other thing you would need to do is modify the frame subroutine so to include the channel number that the servo is connected to, followed by the “SERVO” command. For example, if your extra servo was connected to channel 2, your modified frame subroutine might looks like this:

sub frame
  wait_for_button_press
  1 servo
  2 servo   #this specifies that the new servo is connected to channel 2 and sends the target position
return

If you want your two servos to always have the same motion, an alternative solution to modifying your script could be to use something like a Y Splitter Cable to send the same signal to both servos.

-Brandon