Trying to open a face plate, then close again, and repeat

I am new to this, and don’t know what I am doing, lol
I am trying to open a face plate on my Iron Man helmet, and then close it again. This does include LEDs that turn on and off.
I am trying to start closed with LED on, which is frame 0
Then when I push the button, I want it raise and be open with the LED off, which is completed in frame 1
I want to push the button again, and go back to the original position, in frame 0.

Using a micro maestro 6

I have a switch on 0, and a servo on 1 & 2. I also have an LED strand on 3.

Everything works when I play with the sliders in the Maestro Control Center, but I don’t know how to program the controller.
When I run the script, it just opens and closes over and over and over, however does turn the LED off and on the its supposed too. Looks like I have the frames correct.

Here is what my frames copy over to on the script:

[code]# Open Close
begin
500 8000 2944 6000 frame_1…3 # Frame 0
500 2944 8000 5934 frame_1…3 # Frame 1
repeat

sub frame_1…3
3 servo
2 servo
1 servo
delay
return[/code]

Hello.

There is an example script for using a button and switch to control servos in the “Example Scripts” section of the Maestro user’s guide that can help get you started. You could copy the code there and change the main_loop BEGIN/REPEAT block and frame subroutine to execute your sequence. Like so:

# Uses WAIT_FOR_BUTTON_PRESS to allow a user to step through
# a sequence of positions on servo 1.
main_loop:
begin
  500 8000 2944 6000 frame # Frame 0
  500 2944 8000 5934 frame # Frame 1
repeat
 
sub frame
  wait_for_button_press
  frame_1..3
  return

By the way, we deleted your other post, since it was nearly identical to this post.

- Amanda

Thank you, I was going through the manual, but was a bit overwhelmed. I was not sure of the other post made it or not :slight_smile: Thank you for your help!

Gives me an error: script: 10:3: Did not understand “WAIT_FOR_BUTTON_PRESS”

Ok, so I realized I was misreading. I am not getting an error: Error applying parameters. script:61:3: Did not understand ‘FRAME_1…3’

Here is my code at the moment:

[code]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_10ms
wait_for_button_closed_10ms
return

Wait for the button to be NOT pressed for at least 10 ms.

sub wait_for_button_open_10ms
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 10 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_10ms
get_ms
begin
# reset the time on the stack if it is not pressed
button
if
get_ms over minus 10 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.

Uses WAIT_FOR_BUTTON_PRESS to allow a user to step through

a sequence of positions on servo 1.

main_loop:
begin
500 8000 2944 6000 frame # Frame 0
500 2944 8000 5934 frame # Frame 1
repeat

sub frame
wait_for_button_press
frame_1…3
return[/code]

GOT IT!!! woooooo!!! THANK YOU!

My final code that worked :slight_smile:

[code]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_10ms
wait_for_button_closed_10ms
return

Wait for the button to be NOT pressed for at least 10 ms.

sub wait_for_button_open_10ms
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 10 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_10ms
get_ms
begin
# reset the time on the stack if it is not pressed
button
if
get_ms over minus 10 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.

Uses WAIT_FOR_BUTTON_PRESS to allow a user to step through

a sequence of positions on servo 1.

main_loop:
begin
500 8000 2944 6000 frame # Frame 0
500 2944 8000 5934 frame # Frame 1
repeat

sub frame
wait_for_button_press
sub frame_1…3
3 servo
2 servo
1 servo
delay
return[/code]