Hello,
im from germany.
I have ha problem that i have a sensor that send seqeuns.
I would controll a servo for that with.
but i get a overflow with my script but i don`t now why?
I am new in that. There is the scipt
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_400ms
wait_for_button_closed_400ms
return
# Wait for the button to be NOT pressed for at least 10 ms.
sub wait_for_button_open_400ms
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 400 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_400ms
get_ms
begin
# reset the time on the stack if it is not pressed
button
if
get_ms over minus 400 greater_than
if drop return endif
else
drop get_ms
endif
repeat
sub button1
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_press1
wait_for_button_open_300ms
wait_for_button_closed_300ms
return
# Wait for the button to be NOT pressed for at least 10 ms.
sub wait_for_button_open_300ms
get_ms # put the current time on the stack
begin
# reset the time on the stack if it is pressed
button1
if
drop get_ms
else
get_ms over minus 300 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_300ms
get_ms
begin
# reset the time on the stack if it is not pressed
button1
if
get_ms over minus 300 greater_than
if drop return endif
else
drop get_ms
endif
repeat
sub button2
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_press2
wait_for_button_open_200ms
wait_for_button_closed_200ms
return
# Wait for the button to be NOT pressed for at least 10 ms.
sub wait_for_button_open_200ms
get_ms # put the current time on the stack
begin
# reset the time on the stack if it is pressed
button2
if
drop get_ms
else
get_ms over minus 200 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_200ms
get_ms
begin
# reset the time on the stack if it is not pressed
button2
if
get_ms over minus 200 greater_than
if drop return endif
else
drop get_ms
endif
repeat
sub button3
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_press3
wait_for_button_open_100ms
wait_for_button_closed_100ms
return
# Wait for the button to be NOT pressed for at least 10 ms.
sub wait_for_button_open_100ms
get_ms # put the current time on the stack
begin
# reset the time on the stack if it is pressed
button3
if
drop get_ms
else
get_ms over minus 100 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_100ms
get_ms
begin
# reset the time on the stack if it is not pressed
button3
if
get_ms over minus 100 greater_than
if drop return endif
else
drop get_ms
endif
repeat
sub button4
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_press4
wait_for_button_open_75ms
wait_for_button_closed_75ms
return
# Wait for the button to be NOT pressed for at least 10 ms.
sub wait_for_button_open_75ms
get_ms # put the current time on the stack
begin
# reset the time on the stack if it is pressed
button4
if
drop get_ms
else
get_ms over minus 75 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_75ms
get_ms
begin
# reset the time on the stack if it is not pressed
button4
if
get_ms over minus 75 greater_than
if drop return endif
else
drop get_ms
endif
repeat
sub button5
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_press5
wait_for_button_open_50ms
wait_for_button_closed_50ms
return
# Wait for the button to be NOT pressed for at least 10 ms.
sub wait_for_button_open_50ms
get_ms # put the current time on the stack
begin
# reset the time on the stack if it is pressed
button5
if
drop get_ms
else
get_ms over minus 50 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_50ms
get_ms
begin
# reset the time on the stack if it is not pressed
button5
if
get_ms over minus 50 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
frame
frame1
frame2
frame3
frame4
frame5
repeat
sub frame
wait_for_button_press
if 1
2000 12 servo
else
drop return
endif
sub frame1
wait_for_button_press1
if 1
4000 12 servo
else
drop return
endif
sub frame2
wait_for_button_press2
if 1
6000 12 servo
else
drop return
endif
sub frame3
wait_for_button_press3
if 1
8000 12 servo
else
drop return
endif
sub frame4
wait_for_button_press4
if 1
10000 12 servo
else
drop return
endif
sub frame5
wait_for_button_press5
if 1
12000 12 servo
else
drop return
endif
4 posts - 2 participants