Simplifying it down to just one button for now sounds like a good idea. Using get_ms
is likely going to be much more practical than a blocking delay, especially since you are going to be adding a second button later.
One way to use the get_ms
command for checking a delay like this is to have the current time continuously updating when the button is not pushed, like this:
get_ms #get initial timer value
begin
1 get_position 512 less_than if #check if button is pressed
#the rest of your code goes here
else #if not, drop the current time on the stack and update it with a new one
drop get_ms #you can also add your command for sending the servo to the first position here
endif
repeat
Then, if the button is pressed, you can subtract the current time from the time that was left on the stack. Note that to preserve the value on the stack, you can duplicate it before you use it. Also, to set the parameters for the minus
command to the right order, you can use the swap command, like so:
dup get_ms swap minus #duplicate time on stack and subtract the current time from it
This will place a value on the stack that represents how long the button has been held down in milliseconds, so you can use this to tell if the button has been held down for longer than 10 seconds with another if
statement:
1000 greater_than if
#you can add your command for sending the servo to the second position here
#once the button is released, it will go back to the position 1 set above
endif
As I said in my previous post, if you try modifying or writing your own code that handles this delay, you can post it here, and I would be glad to take a look.
Brandon