I am very new to the world of servos, robotics, and coding so please bear with me!
I have been able to successfully create servo animation sequences using the Maestro Control Center, and I love it. What I want to do now is use a button to start the sequence.
What I have is a Mini Maestro 12 and Gravity Digital Push Button:
I have tried adding some of the sample scripts to use this, but to no avail. I have the button plugged into port 11 and set to input. I can see the response in the status window when I press the button.
With a button like this do I still need to wire a pull-up resistor?
If not, where / how exactly to I add this to the script?
Iāve added my current script below. It would be great if you could help!!
If you are getting the expected behavior when you press the button, it is likely your button already has an integrated pull resistor, so you should not need to add another one. As for programming that behavior, you can see one method described in this post by BrandonM.
Keep in mind though, you will need to change the channel identified in the example script to match the channel you are using. Additionally, if your button logic is inverted, you might need to change āgreater_thanā to āless_thanā.
Can you specify what specific error you are getting by checking the āErrorsā tab in the Maestro Control Center? Also, please post your Maestro settings file; you can save your settings file from the Maestro Control Center under the āFileā menu, with the Maestro connected.
I just noticed that you posted your script in a post on the other thread I mentioned earlier. It looks like the problem is that you added only one line of BrandonMās example to your script instead of making a new loop that acts before the rest of your code. To do that, you need to include the begin/repeat in BrandonMās example, and that section should be placed before the rest of your code, like this:
begin
11 get_position 200 greater_than while #wait in while loop until button connected to channel 11 is pushed
repeat
begin
750 6784 256 13120 3456 10944 0
0 0 0 0 0 frame_0ā¦10 # Start
1000 4814 frame_1 # Tilt Right
1000 256 6125 frame_1_2 # Tilt Left
1000 13120 frame_2 # Face Forward
500 4160 frame_0 # Jaw Open 1
500 6784 frame_0 # Jaw Closed 1
500 4160 frame_0 # Jaw Open 2
1000 6743 frame_0 # Jaw Closed Two
5000 2727 8800 frame_3_4 # Start Pour
1000 3456 10944 frame_3_4 # End Pour
repeat
#and then the rest of your code as you had it before...
Hello Patrick,
Iāve been going through all the posts to do my best to not ask an already answered questionā¦I just havenāt found the answer if itās there. I want to start a sequence with a contact (button) - Iāve found that part. My desire is to start the sequence once the contact is closed, and then ignore the contact (not have any effect on restarting the sequence. Once the sequence is complete, the contact would need to open then re-close to start again. Code is brand new to me but Iām trying my best to work through it. Iām nearly 60 and I remember thinking āpunch cardsā were the future. I apologize for what is probably something simpleā¦Iāve been at it for a couple days and Iām just not getting it.
Thanks
Tim
Patrick,
I should clarify my problem. The contact to start the sequence will probably always be maintained. I just donāt want the sequence to start again until it is opened, the re-closed. Ideally, I donāt want the sequence to restart with any contact activity until it has run till complete. I have used quite a few Maestros, but Iāve always just used ārun from power upā so my knowledge is basic.
Thanks
Tim
It sounds like you just need to add another loop after your sequence that waits until the button is open. So it would be similar to the loop at the beginning of your program, but it would have the opposite condition, like this (assuming the button is connected to pin 11 as in the previous example:
begin
11 get_position 200 less_than while #wait in while loop until button connected to channel 11 is released
repeat
Hello Patrick,
I think I am missing something very basic. Once I create a sequence and I then want to go in to add to the codeā¦what is that process? Iāve been just clicking on the script tab and typing it in, then click apply settings. I must be missing something very simple, because I can duplicate code posted here and get no function. My input switch is working in the status tabā¦it feels like Iām not getting the added code into the script.
Any idea what am I missing?
Tim
Hello All,
Iām new to this but trying to learn. Iāve read much of the Maestro guide and went through every post I can find and Iām still having no luck. I found some helpful infor from Brandon and Patrickā¦but no luck so far.
From BrandonM in post #2, post:2, topic:13603"]
Probably the simplest way to start your script with a button press is to add a WHILE loop to the beginning that exits when the button is pressed. You can find some code for doing this in my post here. Please note that the code there is for a button on channel 5; you can change the 5 to a 0 to make it work for your button on channel 0.
If you put the WHILE loop before your BEGIN/REPEAT loop, the sequence will repeat forever once the button is pressed. If you want the sequence to wait for the button every cycle, you can put the WHILE loop inside of your current BEGIN/REPEAT loop.
Brandon
Can I ask what you mean when you say āinsideā of the BEGIN/REPEAT loop?
Iām still having no luck getting the script to start.
My objective - when I toggle the switch on (pulling input pin 8 low), Iād like the sequence to play once, then wait until the switch is toggled off (pin 8 high), then on again before it plays the sequence once more. this is my current script
Sequence 0
begin 8 get_position 200 less_than while #switch low to start sequence
repeat
begin
3000 3986 3986 3986 3986 0 0
0 0 0 0 0 frame_0ā¦7_9ā¦11 # Frame 0
3000 8000 frame_0 # Frame 1
3000 3986 frame_0 # Frame 2
repeat
begin 8 get_position 200 greater_than while #switch high before restart switch low possible
repeat
I know something is wrong but I canāt figure it out. Iām not able to get the sequence to play at all
Any help would be very much appreciated
Thank you
Tim
Timbot
I apologize for my delayed response. I noticed you posted about this same issue on a few other threads. Letās keep our discussion here so that it is all in one place. (Also, I moved the post from the new thread you started here.)
Based on the code you shared, I suspect your Maestro is probably stuck in a loop where it is constantly waiting for the button to be pressed. To produce the behavior you want, you need to put the loops for your button press and release inside the loop with your servo sequence, i.e. the button loops should be nested loops within the main loop. That will make your script look something like this:
begin
begin 8 get_position 200 less_than while #switch low to start sequence
repeat
3000 3986 3986 3986 3986 0 0
0 0 0 0 0 frame_0ā¦7_9ā¦11 # Frame 0
3000 8000 frame_0 # Frame 1
3000 3986 frame_0 # Frame 2
begin 8 get_position 200 greater_than while #switch high before restart switch low possible
repeat
repeat
By the way, in general, and especially when using nested loops, I strongly recommend indenting and spacing your code appropriately to keep things organized.
Patrick,
Thank you! I never would have figured that out! I just had to swap the less_than/greater_than to give me what I was after (switch pulling input 8 low to start sequence - one run. Switch has to go high, then low again to start sequence again - one run)
If I can ask one more questionā¦Iām probably pushing it, but Ideally Iād like to have four different sequences on this Maestro. They all control the same components, but with different āshow lengthsā and timing. I would like to trigger each sequence with itās own switch. it will have the same behavior as the switch you helped me with. I created another sequence, then I ācopy all sequence to scriptā I then opened the script tab hoping I could just put the same switch behavior code and my eyes exploded! I should have know it wouldnāt be so easy. I have no idea where to apply the code to āsequence 1ā
Can this be done? if so, will the process be the same for sequence 2 and 3? or will the script continue to multiply into a scene from the Matrix?
No matter if you can help with this or not, youāll see another order and Pololu/covid donation from me now. What youāve already helped me with was a life saver!
Thanks
Tim
The easiest way to make something like what you are proposing would probably be to program a control structure using if statements. You can find more information about using if statements in the āThe Maestro Scripting Languageā section of the userās guide, but here is a quick example I wrote for two buttons showing how it might look in your application:
begin
8 get_position # get the value from button connected to pin 8
200 greater_than # test if it is pressed
if
Sequence_0 # if it is pressed, then run Sequence_0
begin 8 get_position 200 less_than while # then wait until the button is released
repeat
endif
9 get_position # get the value from button connected to pin 9
200 greater_than # test if it is pressed
if
Sequence_1 # if it is pressed, then run Sequence_1
begin 9 get_position 200 less_than while # then wait until the button is released
repeat
endif
repeat
Patrick,
Thank you! Because of my switch type (active low) I just swapped a couple of the greater than for less than and it does exactly what I wantā¦runs each sequence one time when the pin is pulled low, and wonāt run it again until the pin goes high, then low again.
Thank you very much for all your help! I really canāt thank you enough!
Tim
begin
8 get_position
200 less_than
if
Sequence_0
begin 8 get_position 200 less_than while
repeat
endif
9 get_position
200 less_than
if
Sequence_1
begin 9 get_position 200 less_than while
repeat
endif
repeat
BTW, I am indenting, but when I cut and paste here it goes away
Hello @PatrickM sorry to butt in, I too am puzzled by coding but found this thread and implemented your recommendations in my script as I thought appropriate.
I have a single momentary push button fitted with a pull up resistor and the switch which grounds the input when pressed.
I would like my sequence to start when the button is pressed and stop at the end.
Cycling the momentary switch shows the change in state in the āstatusā window, normally high, low when pressed.
If disconnect from the PC and power up the Pololu waits for the button to be pressed, before starting, so far so good, but at the end of the sequence it repeats again and again, etc.
When connected to my PC it runs through the sequence once as required.
BTW, I ticked the āRun script on start upā box
Please could you explain what I have done wrong and help me out with a fix?