Hello.
Thank you for posting the scripts you have tried so far and clear descriptions of what they do.
Since your first script is the simplest and seems to be working close to how you want, I recommend starting there. I noticed two things that are potentially causing the problem. The first is that all your sequences have delays in them. This might not be a problem depending on how responsive you want the system, but keep in mind that these delays are blocking, so while the Maestro is commanded to delay, it will not be running any other code in your script. For example, if you press the button and sequence_a runs, it will not respond to another button press for at least 1 second (since there are two half second delays in that sequence).
The second thing I noticed was that your script is using the button subroutines in multiple different places in the loop with different results. The way your code is right now, when no button is being pressed, the script will continuously run through the button_a and button_b subroutines to see if either of them are pressed. Because this same subroutine is being used in multiple IF statements throughout the loop, the sequence that gets called when a button is pressed will be whichever one happens to be in the IF statement currently being processed. This means that if you press button_a and it runs sequence_a, there is a good chance that the next time you press button_a, it will run sequence_a again, instead of sequence_aa.
If you want pressing the same button multiple times to have different outcomes (e.g. switching a servo from position one to position two on the first press, and back to position one on the second press) you will need to have additional logic. One way to do this is using a state variable. You can find an example and explanation for using a state variable in my posts in this thread. Another option is to use the current position of the servo to decide which sequence to call. For example:
button_a if #if button_a is pressed
2 get_position #check the position of servo 2
9000 equals if #if it equals 9000
sequence_a #run sequence_a
else #if it does not equal 9000
sequence_aa #run sequence_aa
endif
endif
By the way, it looks like you might have a typo in your first script. It looks like you probably want button_b to switch between calling sequence_b and sequence_bb, but your last if statement uses button_a again.
Brandon
