goto main_loop
sub button
0 get_position 500 less_than
return
sub wait_for_button
wait_for_button_closed_10ms
return
sub wait_for_button_press_10ms
get_ms
begin
button
if
drop get_ms
else
get_ms over minus 10 greater_than
if drop return endif
endif
repeat
sub wait_for_button_closed_10ms
get_ms
begin
button
if
get_ms over minus 10 greater_than
if drop return endif
else
drop get_ms
endif
repeat
main_loop:
begin
4460 1 servo # first/ starting postion for 1st servo
7616 1 servo # second postion for 1st servo after button press
2000 2 servo # first/ starting for leds
7000 2 servo # second postion for leds after button press
repeat
sub frame
wait_for_button
1 servo
2 servo
wait_for_button_press_10ms
return
this is the code i am running on my mini maestro channel servo controller. im am trying to get it where my servo is in one postion and the leds are off. then press a button and the servo goes to postion two and my leds turn off.
as soon as i run the script my servo starts to go haywire. any help?
sorry correction. where servo 1 is in position one and leds (servo 2) are on and then button is pressed and servo 1 is to position 2 and leds ( servo 2) are off.
Hello.
It looks like you have everything in place to do button debouncing using the wait_for_button
subroutine, but you are never calling it from your main loop. In the beginning of your script, it jumps to the main_loop
label and enters a BEGIN. . .REPEAT
infinite loop that moves your servo back and forth. However, it looks like you have the frame
subroutine set up to handle the button presses. You might try editing your BEGIN. . .REPEAT
loop to call the frame
subroutine instead of setting the servo positions directly, which might look something like this:
main_loop:
begin
2000 #first position LED control
4460 #first position servo position
frame
7000 #second position for LEDs
7616 #second position for servo
frame
repeat
Please note that since the frame
subroutine calls 1 servo
before 2 servo
, I switched the order of the servo and LED positions on the stack in the main loop. This makes it so the top number on the stack (which is the last value put on the stack) going into the subroutine will be the servo position (which is the first one used in the subroutine).
If you try modifying your script and continue having problems, could you post your updated script?
-Brandon