looping with a macro
-
Hello,
I would like to write a macro to facilitate the levelling of the 4 corners (semi automatic movement) on a 3D printer with duet3D as motherboard.
I have the following problem: how can I return to the first point once I have arrived at the last one if I press "OK" (next)?
I want to avoid programming a "fixed" number of turns!
I would like to avoid programming a "frozen" number of laps! Sincerely,
PUSSY -
-
There is only one command I know of that takes user input and gives the user more than one option as a response - M291 using the S3 mode. This mode puts the message up and lets the user select one of two buttons "OK" or "Cancel". You can use this feature to branch your code (return to the first point OR do something else).
The key is that if the user selects the "OK" button, the next line of code in your macro will run, and if they select "cancel", the "current code block" will terminate. So you can do something like this:
var loop = true var answer = "No" while loop loop = False M291 P"Press OK for 'Yes' and Cancel for 'No'. S3 T-1 set var.answer = "Yes"
The while loop is used to make a "code block" - the indented lines are a separate block from the rest of the macro.
Before you enter the loop, you set a variable to use to exit the loop, and also a variable that contains the answer if the person clicks the Cancel button.
You probably only want to make one trip through the loop, so as soon as you enter you set the variable "loop" to false to make this happen.
Then you post your user interface question with an M291. If they click OK, the next line of code is executed and the answer becomes "Yes".
I think you should also be able to do this with an IF statement, but I have not tried that myself. Maybe give it a test and report back here.
var answer = "No" If true M291 P"Press OK for 'Yes' and Cancel for 'No'. S3 T-1 set var.answer = "Yes"