For loop in maestro language

Hi, I want to make a for loop in the pololu control center. And I want to do some math in the loop. I read the manual but I couldn’t find anything about a for loop.
Any help would be greatly appreciated.

Thanks,

Kalvik.

Hello, Kalvik.

There is no FOR loop control statement in the Maestro scripting language. To create your own FOR loop, you would need to use a compilation of commands from the “Command Reference” section of the Maestro User’s Guide. For example, the code below is one way to write it:

  begin dup while      # check if the count has reached zero
    # do some math
    1 minus 1000 delay # subtract one and delay 1s
  repeat

The code above is a snippet of the “Long delays” example, which can be found under the “Example Scripts” section of the user’s guide. It might be helpful for you to follow the “Long delays” script step-by-step using the “Step Script” button in the “Script” tab of the Maestro Control Center to see how the values on the stack change after each command execution.

- Amanda

If I subtract 1 won’t it be removed from the math I did??

As I said in my previous post, the code example is a snippet of the “Long delays” example. It will depend on how you write your script. You could use PEEK and POKE commands (for Mini Maestro 12, 18, and 24 only) to store the result of your math computation at a different position on the stack. For example:

0   # keep adding 10
5   # loop 5 times
begin dup while      	# check if the count has reached zero
    0 peek 10 plus      # copy value from stack position 0 and do some math
    0 poke		        # store result at position 0 on stack
    1 minus 1000 delay  # subtract one from loop and delay 1s
  repeat

If you have a Micro Maestro, you could do something similar using SWAP, ROT, ROLL, or PICK. Please see the Maestro’s user’s guide for more details about how to use those commands.

- Amanda