Gcode macros to change strip led colors while extruder (and bed) reach temperatures

Finally I have my GCODE to: set (in START_PRINT) the extruder and BED temperature and WAIT for them, and while waiting, I can change neopixels strip led colors…

[gcode_macro START_PRINT]
###come usare con cura per esempio: start_print B={material_bed_temperature_layer_0} H={material_print_temperature_layer_0} L={layer_height} S={speed_travel}
default_parameter_B=70
default_parameter_H=230
default_parameter_L=0.2
default_parameter_S=100
gcode:
#  ...  ##some operations...
#  ...
#  ...
  M117 Porto a Home X-Y...
  M118 Porto a Home X-Y...
  G28 X0 Y0
  G4 P1000
  
  #set_led_red
  M117 Riscaldo Piatto e estrusore...
  M118 Riscaldo Piatto e estrusore...
  M140 S{B} ; heat Bed senza attendere
  M104 S{H}
  G4 P1000
  #set_led_yellow
  
  check_temp_1
  
  M117 Attendo Temperatura BED ...
  M118 Attendo Temperatura BED ...
  #set_led_red
  M190 S{B} ###just for security we wait again.....
  M117 Attendo Temperatura HotEND ...
  M118 Attendo Temperatura HotEND ...
  #set_led_red
  M109 S{H} ###just for security we wait again.....
  #set_led_ciano
#  ... 
#  ... some other operations...
#  ...

[gcode_macro check_temp_2]
gcode:
  {% if printer.extruder.temperature < printer.extruder.target %}
     M117 attendo...
     M118 attendo...
     templedcolor_timer
     G4 P1000
  {% endif %}

[gcode_macro check_temp_1]
gcode:
  {% set wipe_count = 1000 %} #1000 seconds, but if extruder temp is ok, in a 1 seconds it reach the 1000 value !!!
  {% for wipe in range(wipe_count) %}
    check_temp_2 
  {% endfor %}  

# Temperature reactive Neopixel using delayed g-code
[gcode_macro templedcolor_timer]
gcode:
  {% if printer.extruder.target|int > 0 %}
    m118 cambio colori mentre scaldo...
    {% if printer.extruder.temperature >= printer.extruder.target %}
        SET_LED LED=neopixel RED=1.00 GREEN=0 BLUE=0
    {% elif printer.extruder.temperature >= (printer.extruder.target-10) %}
        SET_LED LED=neopixel RED=0.95 GREEN=0 BLUE=0.05
    {% elif printer.extruder.temperature >= (printer.extruder.target-20) %}
        SET_LED LED=neopixel RED=0.90 GREEN=0 BLUE=0.10
    {% elif printer.extruder.temperature >= (printer.extruder.target-30) %}
        SET_LED LED=neopixel RED=0.85 GREEN=0 BLUE=0.15
    {% elif printer.extruder.temperature >= (printer.extruder.target-40) %}
        SET_LED LED=neopixel RED=0.80 GREEN=0 BLUE=0.20
    {% elif printer.extruder.temperature >= (printer.extruder.target-50) %}
        SET_LED LED=neopixel RED=0.75 GREEN=0 BLUE=0.25
    {% elif printer.extruder.temperature >= (printer.extruder.target-60) %}
        SET_LED LED=neopixel RED=0.70 GREEN=0.10 BLUE=0.30
    {% elif printer.extruder.temperature >= (printer.extruder.target-70) %}
        SET_LED LED=neopixel RED=0.65 GREEN=0.10 BLUE=0.35
    {% elif printer.extruder.temperature >= (printer.extruder.target-80) %}
        SET_LED LED=neopixel RED=0.60 GREEN=0.10 BLUE=0.40
    {% elif printer.extruder.temperature >= (printer.extruder.target-90) %}
        SET_LED LED=neopixel RED=0.55 GREEN=0.10 BLUE=0.45
    {% elif printer.extruder.temperature >= (printer.extruder.target-100) %}
        SET_LED LED=neopixel RED=0.50 GREEN=0.10 BLUE=0.50
    {% elif printer.extruder.temperature >= (printer.extruder.target-110) %}
        SET_LED LED=neopixel RED=0.45 GREEN=0.20 BLUE=0.55
    {% elif printer.extruder.temperature >= (printer.extruder.target-120) %}
        SET_LED LED=neopixel RED=0.40 GREEN=0.20 BLUE=0.60
    {% elif printer.extruder.temperature >= (printer.extruder.target-130) %}
        SET_LED LED=neopixel RED=0.35 GREEN=0.20 BLUE=0.65
    {% elif printer.extruder.temperature >= (printer.extruder.target-140) %}
        SET_LED LED=neopixel RED=0.30 GREEN=0.20 BLUE=0.70
    {% elif printer.extruder.temperature >= (printer.extruder.target-150) %}
        SET_LED LED=neopixel RED=0.25 GREEN=0.20 BLUE=0.75
    {% elif printer.extruder.temperature >= (printer.extruder.target-160) %}
        SET_LED LED=neopixel RED=0.20 GREEN=0.30 BLUE=0.80
    {% elif printer.extruder.temperature >= (printer.extruder.target-170) %}
        SET_LED LED=neopixel RED=0.15 GREEN=0.30 BLUE=0.85
    {% elif printer.extruder.temperature >= (printer.extruder.target-180) %}
        SET_LED LED=neopixel RED=0.10 GREEN=0.30 BLUE=0.90
    {% elif printer.extruder.temperature >= (printer.extruder.target-190)  %}
        SET_LED LED=neopixel RED=0.05 GREEN=0.30 BLUE=0.95
    {% elif printer.extruder.temperature >= (printer.extruder.target-200) %}
        SET_LED LED=neopixel RED=0 GREEN=0.35 BLUE=1.0
    {% elif printer.extruder.temperature >= (printer.extruder.target-210) %}
        SET_LED LED=neopixel RED=0 GREEN=0.40 BLUE=1.0
    {% endif %}
  {% else %}
    m118 extrusore spento...
  {% endif %}
 

2 Likes

same macro, same result, optimized, less code:

[gcode_macro START_PRINT]
###come usare con cura per esempio: start_print B={material_bed_temperature_layer_0} H={material_print_temperature_layer_0} L={layer_height} S={speed_travel}
default_parameter_B=70
default_parameter_H=230
default_parameter_L=0.2
default_parameter_S=100
gcode:
#  ...  ##some operations...
#  ...
#  ...
  M117 Porto a Home X-Y...
  M118 Porto a Home X-Y...
  G28 X0 Y0
  G4 P1000  
  #set_led_red
  M117 Riscaldo Piatto e estrusore...
  M118 Riscaldo Piatto e estrusore...
  M140 S{B} ; heat Bed senza attendere
  M104 S{H}
  G4 P1000


  check_temp


  #set_led_yellow
  M117 Attendo Temperatura BED ...
  M118 Attendo Temperatura BED ...
  #set_led_red
  M190 S{B} ###just for security we wait again.....
  M117 Attendo Temperatura HotEND ...
  M118 Attendo Temperatura HotEND ...
  #set_led_red
  M109 S{H} ###just for security we wait again.....
  #set_led_ciano
#  ... 
#  ... some other operations...
#  ...


[gcode_macro check_temp]
gcode:
  {% set count = 1200 %} ### about 10 minutes count...
  {% for c in range(count) %}
    templedcolor_timer 
  {% endfor %}  

# Temperature reactive Neopixel using extruder actual temp...
[gcode_macro templedcolor_timer]
gcode:
  {% if printer.extruder.target|int > 0 %}
    {% if printer.extruder.temperature < printer.extruder.target %}
      #M117 ciclico...
      #M118 ciclico... 
      {% set rosso = (printer.extruder.temperature / printer.extruder.target)|round(2) %}
      {% set blu = (1-(printer.extruder.temperature / printer.extruder.target))|round(2) %}
      #M117 rosso={rosso} blu={blu }
      #M118 rosso={rosso} blu ={blu }
      SET_LED LED=neopixel RED={rosso} GREEN=0 BLUE={blu}
      G4 P500
    #{% else %}
      #M117 Fine ciclo...
      #M118 Fine ciclo...
    {% endif %}  
  {% else %}
    m118 extrusore spento...
  {% endif %}