Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

    How to set and use variables

    Scheduled Pinned Locked Moved
    Gcode meta commands
    5
    7
    788
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Rodrigue Richallandundefined
      Rodrigue Richalland
      last edited by

      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 = 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]

      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

      dc42undefined 1 Reply Last reply Reply Quote 0
      • Phaedruxundefined
        Phaedrux Moderator
        last edited by

        Have you seen this? https://docs.duet3d.com/en/User_manual/Reference/Gcode_meta_commands

        Z-Bot CoreXY Build | Thingiverse Profile

        Rodrigue Richallandundefined 1 Reply Last reply Reply Quote 0
        • Rodrigue Richallandundefined
          Rodrigue Richalland @Phaedrux
          last edited by

          @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?

          infiniteloopundefined 1 Reply Last reply Reply Quote 0
          • infiniteloopundefined
            infiniteloop @Rodrigue Richalland
            last edited by

            @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 Richallandundefined 1 Reply Last reply Reply Quote 1
            • dc42undefined
              dc42 administrators @Rodrigue Richalland
              last edited by dc42

              @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]
              endwhile

              Here 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
              

              Duet WiFi hardware designer and firmware engineer
              Please do not ask me for Duet support via PM or email, use the forum
              http://www.escher3d.com, https://miscsolutions.wordpress.com

              Rodrigue Richallandundefined 1 Reply Last reply Reply Quote 0
              • Rodrigue Richallandundefined
                Rodrigue Richalland @infiniteloop
                last edited by

                @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.

                1 Reply Last reply Reply Quote 0
                • Rodrigue Richallandundefined
                  Rodrigue Richalland @dc42
                  last edited by

                  @dc42
                  Thanks you so much for your help and your so detail reply. It's work's. I can use variable now 😊

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post
                  Unless otherwise noted, all forum content is licensed under CC-BY-SA