My gcode_macro is not working

Hi, I made myself following macro:

[gcode_macro SetLED]
description: Set LED colors and area
gcode:
{% set S = params.Start|default(0)|int %}
{% set E = params.End|default(13)|int %}
{% set R = params.Red|default(0)|float %}
{% set G = params.Green|default(0)|float %}
{% set B = params.Blue|default(0.5)|float %}

{% for cnt in range(S, E) %}
SET_LED LED=my_neopixel RED={R} GREEN={G} BLUE={B} INDEX={cnt+1} TRANSMIT=1
{% endfor %}

have one LED strip with 25 LEDs. The macro is just for play, trying out, and stuff for later use. With the macro and its 5 parameters, I want to set the colors of a certain LED range. For example, set the first 13 LEDs to blue and the other 12 to white.

When I replace the default numbers and only press send, it works as expected. However, if I type in another number (between 0.0 and 1.0, of course) using the parameter dropdown window and press send, nothing happens. All LEDs turn off, and that’s it. Does anyone have an idea what is wrong?

What happens if you invoke the macro by typing it out, with the desired parameters, in the console?

1 Like

Nothing. I get no errors, the consol simply says in blue: “SetLED Start=0 End=25 Red=1 Green=1 Blue=1”, like it gets parsed, but nothing happens.

Try this:

[gcode_macro SetLED]
description: Set LED colors and area
gcode:
    {% set S = params.START|default(0)|int %}
    {% set E = params.END|default(13)|int %}
    {% set R = params.RED|default(0)|float %}
    {% set G = params.GREEN|default(0)|float %}
    {% set B = params.BLUE|default(0.5)|float %}

    {% for cnt in range(S, E) %}
        SET_LED LED=my_neopixel RED={R} GREEN={G} BLUE={B} INDEX={cnt+1} TRANSMIT=1
    {% endfor %}

And then invoke with:
SetLED START=0 END=25 RED=1 GREEN=1 BLUE=1

According to the Command Templates documentation, “parameter names are always in upper-case when evaluated in the macro . . . .”

1 Like

dayum, it worked, it was as simple as that. Thank you :slight_smile:

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.