Hi guys,
i need some help please. I am starting a sequenze with a button. When the sequenze ends i hear the servo still spinning and getting warm. Is there a possibility to stop the servo after the button push and the sequence ends, and start the servo again after the second button push to go on with another sequenze?
And a little porblem on top. Sometimes when i push the button, it takes so mich time to start the sequenze sometimes it doesnt start. I am absoultley new in this Pololu bisiness Image may be NSFW.
Clik here to view. .
Here is my code and i am so thankful for any help.
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.2.3.4.5
main_loop:
begin
# Sequence 0
wait_for_button_press
sub Sequence_0
500 0 0 3968 8000 3200 frame_1..5 # Frame 0
500 5824 frame_5 # Frame 1
500 9216 2624 frame_3_4 # Frame 2
repeat
sub frame_1..5
wait_for_button_press
5 servo
4 servo
3 servo
2 servo
1 servo
delay
return
sub frame_5
wait_for_button_press
5 servo
delay
return
sub frame_3_4
wait_for_button_press
4 servo
3 servo
delay
return
7 posts - 2 participants