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

    Turn on neopixel with pause

    Scheduled Pinned Locked Moved
    General Discussion
    3
    18
    717
    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.
    • gringoundefined
      gringo
      last edited by gringo

      I get this error

      Error: Bad command: global.ledState = 0
      Warning: both space and tab characters used to indent blocks at/before line 41
      Error: in file macro line 46 column 28: meta command: unknown variable 'ledState'

      line 46 --> if global.ledState = 0

      dc42undefined OwenDundefined 2 Replies Last reply Reply Quote 0
      • dc42undefined
        dc42 administrators @gringo
        last edited by

        @gringo said in Turn on neopixel with pause:

        I get this error
        Error: Bad command: global.ledState = 0

        Remove the '.' between "global" and "ledState" at line 23.

        Error: in file macro line 46 column 28: meta command: unknown variable 'ledState'

        line 46 --> if global.ledState = 0

        That's a result of the previous error.

        Warning: both space and tab characters used to indent blocks at/before line 41

        As it says.

        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

        1 Reply Last reply Reply Quote 0
        • OwenDundefined
          OwenD @gringo
          last edited by

          @gringo said in Turn on neopixel with pause:

          I get this error

          Well I did say it was untested 🙄

          Error: Bad command: global.ledState = 0

          change this

          if !exists(global.ledState)
          	global.ledState = 0 
          

          to this

          if !exists(global.ledState)
          	global ledState = 0 
          

          Warning: both space and tab characters used to indent blocks at/before line 41

          I don't see any spaces mixed with tabs on my code.
          If you copied and pasted or modified the code you may have introduced some.

          If you use an editor like notepad++ or RJ TextEd, you can set it to display spaces and tabs.

          Notepad ++
          npadplus.gif

          RJ TextEd
          tabs.gif

          1 Reply Last reply Reply Quote 0
          • gringoundefined
            gringo
            last edited by

            Thanks a lot, I will test it today and letting you know what happens

            1 Reply Last reply Reply Quote 0
            • gringoundefined
              gringo
              last edited by

              I´m testing it but all neopixel are shining red . After a while all neopixel turned off.
              Can we create a Macro for testing?

              OwenDundefined 3 Replies Last reply Reply Quote 0
              • OwenDundefined
                OwenD @gringo
                last edited by OwenD

                @gringo
                As I said, I don't have a neopixel.
                It's possible I have made an error with the M150 calls.
                I have modified the code to add some echo commands and fix an error.
                Tt seems to do the loops correctly.
                Please try this and if the echos are correct but the LED control is wrong then you need to focus on the M150 commands to get the on/off correct

                ; 0:/sys/daemon.g
                
                
                if !exists(global.runLED)
                	global runLED = true
                	
                if global.runLED = false ; send "set global.runLED = false" to stop daemon if needed
                	M99 ; exit daemon.  
                
                if !exists(global.ledSize)
                	global ledSize = 58 ; modify to number of LED's in neopixel.
                if !exists(global.ledDelay)
                	global ledDelay = 2 ; modify to change delay. 
                if !exists(global.rLED)
                	global rLED = 255 ; set red value 0 to 255
                if !exists(global.gLED)
                	global gLED = 0 ; set green value 0 to 255
                if !exists(global.bLED)
                	global bLED = 0 ; set blue value 0 to 255
                if !exists(global.wLED)
                	global wLED = 0 ; set red value	0 to 255
                if !exists(global.ledBrightness)
                	global ledBrightness = 255 ; set brightness value 0 to 255
                if !exists(global.ledState)
                	global ledState = 1  ; this will be toggled between 0 and 1 on each loop
                	
                M150 R0 U0 B0 P0 W0 S58 F0  ; turn off neopixels before we start
                
                while true ; create an endless loop
                
                	if global.runLED = false
                		M150 R0 U0 B0 P0 W0 S58 F0  ; turn off neopixels
                		echo "exiting macro"
                		break ; exit loop.
                	if state.status ="processing" ; check if we are printing
                		;toggle the LED state at each loop
                		if global.ledState = 0
                			set global.ledState = 1
                		else
                			set global.ledState = 0
                		;loop through all the LED's
                		while iterations < global.ledSize - 1 ; set to 1 less than number of LED's in neopixel
                			if global.runLED = false
                				M150 R0 U0 B0 P0 W0 S58 F0  ; turn off neopixels
                				echo "exiting loop"
                				break
                			if global.ledState = 0
                				echo "next LED on " , iterations
                			else
                				echo "Next LED off" , iterations
                			M150 R{global.rLED} U{global.gLED} B{global.bLED} W{global.wLED} P{global.ledState = 1 ? global.ledBrightness : 0} S1 F1     ; set next LED in loop to either brightness or off
                			G4 S{global.ledDelay}
                		M150 R{global.rLED} U{global.gLED} B{global.bLED} W{global.wLED} P{global.ledState = 1 ? global.ledBrightness : 0} S1 F0     ; set last LED in loop
                		echo "last LED"
                		G4 S{global.ledDelay}
                	else
                		M150 R0 U0 B0 P0 W0 S58 F0  ; turn off neopixels if we have stopped printing
                		G4 S{global.ledDelay}
                	G4 S{global.ledDelay}
                		
                if global.runLED = false
                	M150 R0 U0 B0 P0 W0 S58 F0  ; turn off neopixels
                	echo "exiting daemon"
                	M99 ; exit daemon.
                		
                if state.status !="processing"
                	G4 S1 ; if we aren't printing add a delay to give control back to processor
                

                File
                daemon.g

                1 Reply Last reply Reply Quote 0
                • OwenDundefined
                  OwenD @gringo
                  last edited by

                  @gringo
                  To update daemon.g you must first rename it to say daemon.g.old
                  Then upload your new version.
                  It wouldn't hurt to restart after that.

                  1 Reply Last reply Reply Quote 0
                  • OwenDundefined
                    OwenD @gringo
                    last edited by

                    @gringo
                    I may have not understood how M150 works correctly.
                    I was assuming that each command was applied immediatly and the F parameter only represented where the sequence started.
                    However this piece of information from the documentation suggests that is incorrect and the only F0 commands are applied.
                    The specified RGB values will be sent to the number of LEDs in the LED strip as specified by the S parameter, pushing the existing colours along the strip. To set all the LEDs the same colour, make the S parameter equal to or a little longer than the number of LEDs in the strip

                    Based on that, try this code instead

                    ; 0:/sys/daemon.g
                    
                    
                    if !exists(global.runLED)
                    	global runLED = true
                    	
                    if global.runLED = false ; send "set global.runLED = false" to stop daemon if needed
                    	M99 ; exit daemon.  
                    
                    if !exists(global.ledSize)
                    	global ledSize = 58 ; modify to number of LED's in neopixel.
                    if !exists(global.ledDelay)
                    	global ledDelay = 2 ; modify to change delay. 
                    if !exists(global.rLED)
                    	global rLED = 255 ; set red value 0 to 255
                    if !exists(global.gLED)
                    	global gLED = 0 ; set green value 0 to 255
                    if !exists(global.bLED)
                    	global bLED = 0 ; set blue value 0 to 255
                    if !exists(global.wLED)
                    	global wLED = 0 ; set red value	0 to 255
                    if !exists(global.ledBrightness)
                    	global ledBrightness = 255 ; set brightness value 0 to 255
                    if !exists(global.ledState)
                    	global ledState = 1  ; this will be toggled between 0 and 1 on each loop
                    	
                    M150 R0 U0 B0 P0 W0 S58 F0  ; turn off neopixels before we start
                    
                    while true ; create an endless loop
                    
                    	if global.runLED = false
                    		M150 R0 U0 B0 P0 W0 S58 F0  ; turn off neopixels
                    		echo "exiting macro"
                    		break ; exit loop.
                    	if state.status ="processing" ; check if we are printing
                    		;toggle the LED state at each loop
                    		if global.ledState = 0
                    			set global.ledState = 1
                    		else
                    			set global.ledState = 0
                    		;loop through all the LED's
                    		while iterations < global.ledSize - 1 ; set to 1 less than number of LED's in neopixel
                    			if global.runLED = false
                    				M150 R0 U0 B0 P0 W0 S58 F0  ; turn off neopixels
                    				echo "exiting loop"
                    				break
                    			if global.ledState = 0
                    				echo "next LED on " , iterations
                    				M150 R{global.rLED} U{global.gLED} B{global.bLED} W{global.wLED} P{global.ledBrightness} S1 F0
                    			else
                    				echo "Next LED off" , iterations
                    				M150 R0 U0 B0 W0 P0 S1 F0     ; set next LED in loop to either brightness or off
                    			G4 S{global.ledDelay}
                    	else
                    		M150 R0 U0 B0 P0 W0 S58 F0  ; turn off neopixels if we have stopped printing
                    		G4 S{global.ledDelay}
                    	G4 S{global.ledDelay}
                    		
                    if global.runLED = false
                    	M150 R0 U0 B0 P0 W0 S58 F0  ; turn off neopixels
                    	echo "exiting daemon"
                    	M99 ; exit daemon.
                    		
                    if state.status !="processing"
                    	G4 S1 ; if we aren't printing add a delay to give control back to processor
                    
                    gringoundefined 1 Reply Last reply Reply Quote 0
                    • gringoundefined
                      gringo @OwenD
                      last edited by

                      @OwenD

                      Only the first Neopixel turns on. The display shows me counts of cylces and the count of enabled Neopixel.
                      In the first pass of all 58 neopixels, only the first one lights up. it is counted up to 56, then the first neopixel goes out again and stays out. It counts up to 56 again and then it starts all over again

                      OwenDundefined 1 Reply Last reply Reply Quote 0
                      • OwenDundefined
                        OwenD @gringo
                        last edited by

                        @gringo
                        Ok
                        I'm clearly not up with M150 so hopefully someone else can help

                        All I can suggest is changing this

                        		;loop through all the LED's
                        		while iterations < global.ledSize - 1 ; set to 1 less than number of LED's in neopixel
                        			if global.runLED = false
                        				M150 R0 U0 B0 P0 W0 S58 F0  ; turn off neopixels
                        				echo "exiting loop"
                        				break
                        			if global.ledState = 0
                        				echo "next LED on " , iterations
                        				M150 R{global.rLED} U{global.gLED} B{global.bLED} W{global.wLED} P{global.ledBrightness} S1 F0
                        			else
                        				echo "Next LED off" , iterations
                        				M150 R0 U0 B0 W0 P0 S1 F0     ; set next LED in loop to either brightness or off
                        			G4 S{global.ledDelay}
                        

                        To this

                        		;loop through all the LED's
                        		while iterations < global.ledSize 
                        			if global.runLED = false
                        				M150 R0 U0 B0 P0 W0 S58 F0  ; turn off neopixels
                        				echo "exiting loop"
                        				break
                        			if global.ledState = 0
                        				echo "next LED on " , iterations
                        				M150 R{global.rLED} U{global.gLED} B{global.bLED} W{global.wLED} P{global.ledBrightness} S{iterations+1} F0
                        			else
                        				echo "Next LED off" , iterations
                        				M150 R0 U0 B0 W0 P0 S{iterations +1} F0     ; set next LED in loop to either brightness or off
                        			G4 S{global.ledDelay}
                        
                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post
                        Unless otherwise noted, all forum content is licensed under CC-BY-SA