How to use If command for Led_on / Led_off

goto main_loop

sub button
5 get_position 500 less_than
return

sub wait_for_button_press
wait_for_button_open_10ms
wait_for_button_closed_10ms
return

sub wait_for_button_open_10ms
get_ms # put the current time on the stack
begin
button
if drop get_ms
else get_ms over minus 10 greater_than
if drop return endif
endif
repeat

sub wait_for_button_closed_10ms
get_ms
begin
button
if get_ms over minus 10 greater_than
if drop return endif
else drop get_ms endif
repeat

main_loop:
begin
800 0 frame
8000 60 frame #change second number on sec you want to release.
repeat

sub frame
wait_for_button_press
delay_seconds
0 servo
return

sub delay_seconds
begin dup while
1 minus 1000 delay
repeat
drop return

Can somebody help me to add led_on Led_off command on my main loop.
When frame is 8000 i need led_on
when frame is 800 i nedd led_off thank you.

and if is not very difficult i prefer when led is on to blinking. thank you.

Hello.

To turn the Maestro’s red LED on (solidly) and off when your servo is at those positions, your main_loop could be:

main_loop:
  begin
    800 0 frame 
    led_off
    8000 60 frame #change second number on sec you want to release.
    led_on
  repeat

Please note that that modification only updates the status of the Maestro’s on-board LED immediately after the position command is sent to the servo. It will not necessarily indicate the servo’s actual position (which the controller does not know), for example before the Maestro has sent the first command.

Getting the red LED to blink is more complicated since it would need to be toggled while the script is waiting for a button press or delay, so it would require the code to be changed more extensively.

-Jon

This way the led opens after the count of 60 seconds. i need this as a sign that starts count the diverse time.

It is not entirely clear to me what you mean when you say “starts count the diverse time”. If you explain in more much detail specifically what behavior you want to observe from the Maestro and when, I might be able to offer suggestions.

-Jon

Push button servo moves back. Led is off
Push button servo delay 60 sec and then moves forward.
I need this 60 sec of delay till the servo moves led blinking.

As long as your first frame passes 0 seconds to the delay_seconds subroutine, something like this should work:

sub delay_seconds
  begin dup while
    1 minus 
    led_on 500 delay #turn LED on; wait 500ms
    led_off 500 delay #turn LED off; wait 500ms
  repeat
  drop 
  return

You can adjust the values placed onto the stack before the delay commands to adjust the LED blinking frequency. Just be sure the total amount of delay equals one full second.

-Jon

thank you very much. I am too close to finish my project. The last i need is to change the time when i press long the button.

main_loop:
begin
800 0 frame
8000 60 frame #change second number on sec you want to release.
repeat

60 becomes 90 120 40.

If you want to wait for the button to be pressed and also detect how long it was pressed for, you can use this subroutine:

sub wait_for_button_press_and_measure_time
  wait_for_button_press get_ms wait_for_button_open_10ms get_ms swap minus
  return

-Jon

please can you add this to my code .
I just need when press long button to change the seconds wait till open for 30-45-60-90-120 sec.
thank you

It is not entirely clear how you want the delay to be modified for a given length of time that the button is held down. For example, specifically what length of time is associated with switching between 30 and 45 seconds or from 90 to 120 seconds? If your plan is to move sequentially between each of those lengths of a delay so long as the button is held down long enough (e.g. as long as the button is held down for at least N number of milliseconds, move the delay from A seconds to B seconds, or from B to C, etc.) how long does the long press need to be held down?

Also, it sounds like you have not made an attempt at modifying your script. If you post what code you have tried, along with a more detailed description of how you want the delay to change based on the length of the delay, I might be able to offer some suggestions.

-Jon

short button press open servo short button press close servo (this is ready as it is on code)
long press change time from 60 to 90
long press change time 90 to 120 etc.
Thank you.

It looks like you did not try to modify your code. Is there something in particular that you do not understand that is preventing you from making an attempt?

-Jon

i am 40 yo and not easy to learn. I have an experience in Delphi (Pascal) and all this look very diffirent to me.

We cannot just write your programs for you, but I would be happy to help you understand how to write a script like that yourself. I recommend trying to understand how our simpler Maestro example scripts work, and then you can try piecing together what you understand and modify the script we have already worked on. If you run into trouble, you can post what code you have tried and I can try to help.

In this specific case, it seems like what you are trying to do might be very difficult using the Maestro scripting language, so you might instead consider using a separate microcontroller (possibly one that supports a language you might be more comfortable programming in) for the logic. If you use an Arduino-based microcontroller, you could use our Maestro Arduino library to command your Maestro through its serial interface.

-Jon