Macro interrupt

Basic Information:

Printer Model: Ender 3v2

Describe your issue:

I’m looking for some advice on how to proceed with a macro I want to create. I have some pixels in my enclosure that I use as a light source but I want to expand on that. The first macro I’d like to write is to have a portion of them flash for an extend period of time (30 minutes or so) or until an acknowledgment with a button. Calling the button and making them flash isn’t an issue. What I’m struggling with is finding a way to interrupt the flashing with a button. This would be an easy task in other languages but Jinja2 doesn’t support interrupts, Do or While loops. I thought about making a for loop with a large count and pass a variable of a much smaller number to the loop with the button to stop it but I’m having a hard time finding how to pass variables between macros and I doubt that would work anyway since the flash macro would already be running.

Can you great folks give me some ideas on how to get around this limit? I’m not new to programming (not an expert either) but Jinja2 is very new and very different to me.

Thanks in advance.

In your flash macro, you could use delayed_gcode. Example:

[gcode_macro FLASH]
gcode:
    UPDATE_DELAYED_GCODE ID=flash_on DURATION=1

[delayed_gcode FLASH_ON]
gcode:
    // Turn on LEDs
    {% if some_condition %}
        UPDATE_DELAYED_GCODE ID=flash_off DURATION=1
    {% endif %}

[delayed_gcode FLASH_OFF]
gcode:
    // Turn off LEDs
    {% if some_condition %}
        UPDATE_DELAYED_GCODE ID=flash_on DURATION=1
    {% endif %}

To pass the variables to these delayed_gcodes, you could use save_variables, and replace some_condition (in the example above) with:

printer.save_variables.variables.do_flash|int == 1

Then you could enable/disable flash with:

[gcode_macro ENABLE_FLASH]
gcode:
    SAVE_VARIABLE NAME=do_flash VALUE=1

[gcode_macro DISABLE_FLASH]
gcode:
    SAVE_VARIABLE NAME=do_flash VALUE=0
1 Like

Perfect! I will give this a try. It looks like a great start. Thank you!

1 Like

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