I have a button connected to a Maestro Mini 6 on P0 and a servo connected to P2 and P3. When pressing the button initially the code below executes the, Extend_Left subroutine, which rotates servo 3 90 degrees then servo 2 90 degrees. When I press the button again the Retract_Left subroutine executes, and servo 2 moves 90 degrees back to initial position and servo 3 the same. All is good!
I’m looking for the code in the “IF” loops to add another button that will act independently and do the same thing but executing subroutines Extend_Right and Retract_Right, with servos connected to P4 and P5.
Any ideas???
1 #Sets an initial state (open)
begin
0 get_position
1 less_than #Check if button is pushed
if
dup
if
Extend_Left #Run the Extend_Left subroutine
drop #Change the state to 0
0
else
Retract_Left #Run the Retract_Left subroutine
drop #Change the state to 1
1
endif
endif
repeat
### Sequence subroutines: ###
# Extend_Left
sub Extend_Left
3 get_position #check the position of servo 1
4000 equals if #see if it is equal to 4000
8000 #if it is, set new target of 8000
else
4000 #if it is not, set new target of 4000
endif
3 servo 900 delay #send the target position to servo 1
2 get_position #check the position of servo 1
4000 equals if #see if it is equal to 4000
8000 #if it is, set new target of 8000
else
4000 #if it is not, set new target of 4000
endif
2 servo 900 delay #send the target position to servo 1
return
# Retract_Left
sub Retract_Left
2 get_position #check the position of servo 1
4000 equals if #see if it is equal to 4000
8000 #if it is, set new target of 8000
else
4000 #if it is not, set new target of 4000
endif
2 servo 900 delay #send the target position to servo 1
3 get_position #check the position of servo 1
4000 equals if #see if it is equal to 4000
8000 #if it is, set new target of 8000
else
4000 #if it is not, set new target of 4000
endif
3 servo 900 delay #send the target position to servo 1
return