6 channel Servo Controller and switch

Dear,

I am quite new in this field. Currently I have 6 channel Servo Controller, where I connected on channel 1 switch and on channel 5 servo, so basically switch will trigger servo to carry out certain sequence (2 frames).
I connected everything as I should and I was also looking at example code in user manual.
Because I am quite new in this, complete newbie, can I ask someone to help to compose script that will run my script when switch will give signal.

Already many thanks in advance for help

Hello.

Have you looked at the “Using a button or switch to control servos” script under the “Example Scripts” section of the Maestro User’s Guide? If you try modifying that script to execute your sequence and run into problems, you can post your script here, and I would be happy to take a look.

- Amanda

I currently have this (copy of example with only 2 frames in), it works now, but to go from frame to frame I need to press button every time. What I am looking is when I press button that the whole sequence (2 frames) will be carried out.

Thanks for help

[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
4966 frame
6962 frame
repeat

sub frame
wait_for_button_press
1 servo
return[/code]

If you want both actions to happen with a single push of the button, you can move wait_for_button_press outside of the frame subroutine and put it right after begin in your main loop. So the new main loop might look something like:

main_loop: begin wait_for_button_press 4966 frame 6962 frame repeat
And your new frame subroutine would be:

sub frame 1 servo return
However, this would likely result in the servo twitching, since there would not be enough time between the servo commands for the servo to reach the target position. You might consider adding a delay in the frame subroutine. You could put the delay after 1 servo then specify the length of the delay before each servo target in the main loop. For example, the frame subroutine with the delay would look like:

sub frame 1 servo delay return
And your main loop would change to something like:

main_loop: begin wait_for_button_press 1000 4966 frame #the first value (1000) specifies the delay duration and the second value (4966) is still the target 1000 6962 frame repeat
This example uses a delay of 1000ms; you will probably want to adjust that value to something appropriate for your application.

-Brandon