How to set and use variables
-
Hello,
For a multiples sub-assembly of my DIY printer, i need to create custom fonctionality using macros.But i dont really understood how to use variables whith in duet3D environement.
in this exemple below, i want to create flash light macro. After many try, the syntaxe look's good, but the macro never stop.
var nbr_de_cycles=50
var i = 0while var.i < var.nbr_de_cycles
M106 P4 S255 ; Allumer la sortie ventilateur à 100%
G4 P100 ; Attendre 50 millisecondes
M106 P4 S0 ; Éteindre la sortie ventilateur
G4 P100 ; Attendre 50 millisecondes
set var.i = [var.i + 1]endwhile
In general, i want to know :
-How to create a variable ?
-How to use a variable value in a calcul ?
-How to make a counter ?Thanks for your help,
Rodrigue -
Have you seen this? https://docs.duet3d.com/en/User_manual/Reference/Gcode_meta_commands
-
@Phaedrux
Of course. After others try today, i think the macro calculation is much slower when the mainbord printing.
Is it possible that the processor is saturating? -
@Rodrigue-Richalland said in How to set and use variables:
i think the macro calculation is much slower when the mainbord printing.
Is it possible that the processor is saturating?Sure! The limited resources of a micro-controller are first and foremost allocated to the job it has to perform, not to a light show to illuminate the job in iterations of some (50) milliseconds. Also, please take into account the nature of scripts: they are interpreted, which imposes additional load on the MCU just to "understand" the meaning of the code.
To generate really fast visual effects, you should use a dedicated controller like an Arduino or ESP. This one might then be triggered by (or synchronised with) certain events on the Duet.
-
@Rodrigue-Richalland said in How to set and use variables:
var nbr_de_cycles=50
var i = 0
while var.i < var.nbr_de_cycles
M106 P4 S255 ; Allumer la sortie ventilateur à 100%
G4 P100 ; Attendre 50 millisecondes
M106 P4 S0 ; Éteindre la sortie ventilateur
G4 P100 ; Attendre 50 millisecondes
set var.i = [var.i + 1]
endwhileHere is what I believe to be a corrected version (not tested) - note that the indentation is important because it defines the scope of the while-command
var nbr_de_cycles=50 var i = 0 while var.i < var.nbr_de_cycles M106 P4 S255 ; Allumer la sortie ventilateur à 100% G4 P50 ; Attendre 50 millisecondes M106 P4 S0 ; Éteindre la sortie ventilateur G4 P50 ; Attendre 50 millisecondes set var.i = var.i + 1
Here is a simpler version that makes use of the built-in variable 'iterations':
var nbr_de_cycles=50 while iterations < var.nbr_de_cycles M106 P4 S255 ; Allumer la sortie ventilateur à 100% G4 P50 ; Attendre 50 millisecondes M106 P4 S0 ; Éteindre la sortie ventilateur G4 P50 ; Attendre 50 millisecondes
-
@infiniteloop said in How to set and use variables:
al effects, you should use a dedicated controller like an Ar
Thanks for your reply. I understand the issue. I will work on new way with arduino and GPIO port of duet.
-
@dc42
Thanks you so much for your help and your so detail reply. It's work's. I can use variable now