6 channel Servo Controller and switch


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


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

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 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
# reset the time on the stack if it is pressed
drop get_ms
get_ms over minus 10 greater_than
if drop return endif

Wait for the button to be pressed for at least 10 ms.

sub wait_for_button_closed_10ms
# reset the time on the stack if it is not pressed
get_ms over minus 10 greater_than
if drop return endif
drop get_ms

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.

4966 frame
6962 frame

sub frame
1 servo

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.