Hello! I have 6 channel maestro and I have attached 3 momentary buttons to operate 3 servos. These are all operational as viewed in the control center with attached resistors and are wired correctly.
I want the start position for each controller to be 752 (min) - I selected this setting in the Control Center so it is not in the script. When I push the button for the first time, I want the servo to go to 1264 (max) - I also selected this setting in the Control Center so it is not in the script. When I push the button the second time, I want the servo to go back to the original 752 (min) when pushed a third time I want the servo to go to 1264 (max) etc.
When I start the script below, buttons A and B will work once, thereafter only button c works and button c continues to work every time I push it going back and forth to the two positions as desired but the other 2 buttons will not work again until I restart the script. I would like to be able to press any button at any time and have it work and take the servo back to the previous setting. I have copied the script below. Can you take a look and let me know what I need to do?
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_a_press
wait_for_button_a_open_10ms
wait_for_button_a_closed_10ms
return
# Wait for the button to be NOT pressed for at least 10 ms.
sub wait_for_button_a_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_a_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
7822 frame
3084 frame
repeat
sub frame
wait_for_button_a_press
1 servo
goto second_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 buttonb
2 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_buttonb_press
wait_for_buttonb_open_10ms
wait_for_buttonb_closed_10ms
return
# Wait for the button to be NOT pressed for at least 10 ms.
sub wait_for_buttonb_open_10ms
get_ms # put the current time on the stack
begin
# reset the time on the stack if it is pressed
buttonb
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_buttonb_closed_10ms
get_ms
begin
# reset the time on the stack if it is not pressed
buttonb
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.
second_loop:
begin
7822 second
3084 second
repeat
sub second
wait_for_buttonb_press
3 servo
goto third_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 buttonc
4 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_buttonc_press
wait_for_buttonc_open_10ms
wait_for_buttonc_closed_10ms
return
# Wait for the button to be NOT pressed for at least 10 ms.
sub wait_for_buttonc_open_10ms
get_ms # put the current time on the stack
begin
# reset the time on the stack if it is pressed
buttonc
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_buttonc_closed_10ms
get_ms
begin
# reset the time on the stack if it is not pressed
buttonc
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.
third_loop:
begin
7822 third
3084 third
repeat
sub third
wait_for_buttonc_press
5 servo
return
Thanks!!!
Alan
801-660-8464