Configuring the effects

※Introduction

In the previous chapter, we discussed how to configure different types of LED strips. In this chapter, we will explain in detail how to set up lighting effects.

Let's assume we have a VORON 2.4 printer.

On the Stealthburner toolhead, we have installed an LED strip containing 3 SK6812 LEDs, and we have correctly specified the pin, number of LEDs, and color order in the led_effects.cfg file:

[neopixel hotend_light]
pin: EBBCan:gpio16      # Replace with the actual pin used for RGB LEDs
chain_count: 3          # Number of LEDs in the RGBW strip
color_order: GRBW       # Color order for RGBW LEDs

Additionally, we have installed two PCB strips on the frame, each containing 18 WS2812 LEDs. These strips are connected in parallel to the mainboard, with pin, LED count, and color order accurately configured in the led_effects.cfg file.

[neopixel frame_light]
pin: PB0      # Replace with the actual pin used for RGB LEDs
chain_count: 18          # Number of LEDs in the RGBW strip
color_order: GRB       # Color order for RGBW LEDs

Please note that the above configuration is for reference only. When configuring in practice, be sure to use the actual pin names, the actual number of LEDs in the strip, and the correct color order.

-Parallel Connection

In a parallel connection, all LED strips display the same effect synchronously, and it is not possible to control a single LED independently.

-Series Connection

In a series connection, each LED can be precisely controlled, allowing for unique effects to be defined for each light.

※Experiment

Now we want all LED devices to light up with a breathing effect when the printer successfully starts and connects to Klipper. We have written a configuration and added it to the led_effects.cfg file, defining a custom lighting effect called light_start:

[led_effect light_start]
autostart: true
recalculate:false
frame_rate: 24
leds:
    neopixel:hotend_light
    neopixel:frame_light  
layers:
    breathing 10 1 top (.5, .5, 1)

After saving and restarting, you'll be pleasantly surprised to see that the configured LEDs all light up with a nearly white light, gradually increasing and decreasing in brightness, simulating the rhythm of breathing and creating a smooth brightness transition.

Next, we will break down the light_start effect configuration line by line, helping you understand the creation of lighting effects in detail.


  • Line 1 [led_effect light_start] The led_effect field is fixed. After the space, enter the name you want to define, using _ to replace spaces in the name.


  • Line 2 autostart: true

Entering true indicates that this light effect will automatically start when the printer powers on.

Entering false, which means the effect will not start automatically and will need to be activated manually.


Line 3 recalculate:false

Enable layer template recalculation on effect activation.


  • Line 4 frame_rate: 24 This sets the frame rate of the effect (in frames per second).


  • Line 5 leds: The leds label is fixed. Below this line, list the LED strips you want to use, prefixed with neopixel: followed by the LED name. For example, in the above configuration, we listed hotend_light and frame_light. You can choose to include one or more.Make sure there is no space between the colon and the LED strip name; otherwise, it may not be recognized.

 leds:
    neopixel:hotend_light
    neopixel:frame_light

You can also specify which specific LEDs to display the effect by providing their indices after the strip name. The indices can be given as a list or a range. You can even invert the range to change the effect. If no indices are specified, the entire strip will be used.Additionally, if needed, the same strip can be included multiple times in an effect, allowing for different emitters to be specified.

Ensure there is a space between the LED strip name and the uppercase parentheses (), or copy directly from here: ().

Example:

leds: 
    neopixel:hotend_light (3-1)   # Uses LEDs 3 to 1 from hotend_light (inverted range)
    neopixel:frame_light (1-9)    # Uses LEDs 1 to 9 from frame_light
    neopixel:frame_light (18-10)  # Uses LEDs 18 to 10 from frame_light (inverted range)

  • Line 8 layers: The layers label is fixed. Below this line, place the definitions for the lighting effect layers. Each line represents a layer, and you can define multiple layers and use special commands to blend them, a concept we can discuss in more detail later.

layers:
    breathing 10 1 top (.5, .5, 1)

Effect Layer Analysis in Line 8

In the effect layer, we use a combination of words and numbers, which may seem complex at first glance. However, it can actually be broken down into five fundamental modules, each contributing to form a complete effect layer:

  1. Layer Name Each layer has a unique name for identification and referencing. In the table below, there are 24 example layer names, such as breathing or linearfade. As the names suggest, the breathing layer achieves a breathing effect, while linearfade creates a linear fade-in and fade-out effect.

  2. Effect Rate For most layers, this parameter controls the speed of the effect’s updates, typically measured in frames. For instance, setting it to 10 means the effect updates 10 times per second. However, in some specific effect layers, this parameter might have a different function.

  3. Cutoff The cutoff parameter sets the starting or ending point of the effect, determining when the effect should begin or stop. Similar to the effect rate, cutoff may have varied meanings depending on the effect layer type.

  4. Blending Mode Blending mode defines how the current layer combines with other layers. Common blending modes include add (overlay), subtract (subtraction), and others, which allow more complex effects. This is a more advanced feature, so if interested, you may explore additional details after this section.

  5. Color Palette The length of the palette is unlimited, with colors defined as groups of red, green, blue, and (optional) white. The white channel is only used for RGBW LEDs and will be ignored on RGB LEDs. The range for each color is a decimal number from 0.0 to 1.0. For white, you can use (1.0, 1.0, 1.0) on RGB LEDs or (0.0, 0.0, 0.0, 1.0) on RGBW LEDs.

Depending on the type of layer, you can fill one or more color values in the palette. Each color must be enclosed in parentheses and separated by commas, with each color group also enclosed in parentheses.

Example 1 For instance, when using the linearfade layer, you can specify blue (0,0,1) and red (1,0,0). This will create a lighting effect that gradually transitions from blue to red over a 3-second period.

layers:  
       linearfade 3 0 top (0,0,1),(1,0,0)  

Example 2 When using the twinkle layer, you can fill the palette with colors like red: (1,0,0), orange: (1,0.647,0), yellow: (1,1,0), green: (0,1,0), cyan: (0,1,1), blue: (0,0,1), and purple: (0.5,0,0.5). This will create a lighting effect that randomly twinkles through seven colors, resembling a disco effect, right?

layers:  
       twinkle 50 .25 top (1,0,0),(1,0.647,0),(1,1,0),(0,1,0),(0,1,1),(0,0,1),(0.5,0,0.5)  

Layer typical example

1. Regular Effect Layers

2. Heater Control Effect Layers

Specifies which heater to use for a heater effect. #Use extruder for the extruder heater and heater_bed for the bed heater. Example:

[led_effect light_start]
autostart: true
recalculate:false
frame_rate: 24
leds:
    neopixel:hotend_light 
layers:
    temperature 10 200 top (0,0,1),(1,0,0)
heater: extruder 
#heater:heater_bed 
#heater:"temperature_fan myfan" 

For temperature fans or sensors, include the type in quotes.

3. Stepper Control Effect Layer

Specifies the axis to be used for the stepper effect. Possible values are x, y, and z.

[led_effect light_start]
autostart: true
recalculate:false
frame_rate: 24
leds:
    neopixel:frame_light 
layers:
    stepper 4 4 top (.5, .5, 1)
stepper:x

4. Limit Switch Trigger Effect Layer

Lists the endstops that the homing effect will trigger. You can specify multiple endstops as a comma-separated list. Possible values are x, y, z, and probe. #Example: endstops: x, y

[led_effect light_start]
autostart: true
recalculate:false
frame_rate: 24
leds:
    neopixel:frame_light 
layers:
    homing 1 0 top (.5, .5, 1)
endstops: x, y

5. Button Trigger Effect Layer

Lists the pins that trigger the button effect. You can specify multiple pins as a comma-separated list, and the effect will trigger when any button is pressed. You can also use already assigned pins (like endstop pins) by employing duplicate_pin_override (refer to the Klipper documentation for more details). Example: button_pins: PC1, PC2.

[led_effect light_start]
autostart: true
recalculate:false
frame_rate: 24
leds:
    neopixel:frame_light 
layers:
    SwitchButton 1 1 top (.5, .5, 1)
button_pins: PC1, PC2

6.AnalogPin Effect Layers

Indicates the pin used for effects that rely on an analog signal.

[led_effect light_start]
autostart: true
recalculate:false
frame_rate: 24
leds:
    neopixel:frame_light 
layers:
    analogpin 10 40 top (.5, .5, 1)
analog_pin:PA1

※Controlling the effects

Active vs. Inactive Effects

  • Active effects generate color data, while inactive effects do not.

Activating and Deactivating Effects

  • To activate an effect, use SET_LED_EFFECT EFFECT=light_start

  • To replace all currently active effects with a new one, use SET_LED_EFFECT EFFECT=light_start REPLACE=1

  • To stop a specific effect, use SET_LED_EFFECT EFFECT=light_start STOP=1

  • To stop all effects, use STOP_LED_EFFECTS

  • To stop effects on specific LEDs, specify the LEDs with STOP_LED_EFFECTS LEDS="neopixel:panel_ring", or indicate LED indices, e.g., STOP_LED_EFFECTS LEDS="neopixel:panel_ring (1-7)". Note: only one LED parameter can be specified per command.

Fading Effects

  • To fade an effect in or out, specify FADETIME:

    • Fade in: SET_LED_EFFECT EFFECT=light_start FADETIME=1.0 (one second).

    • Fade out: SET_LED_EFFECT EFFECT=light_start STOP=1 FADETIME=1.0

    • To fade out all effects, use STOP_LED_EFFECTS FADETIME=1.0

  • Crossfade between effects by combining REPLACE and FADETIME: SET_LED_EFFECT EFFECT=light_start REPLACE=1 FADETIME=1.0

Restarting Effects

  • To resume an effect from its last state, start it normally. To restart from the beginning, add RESTART=1: SET_LED_EFFECT EFFECT=light_start RESTART=1.

Template Processing

Effect Layers as Templates

  • Effects use templates similar to Klipper macros, though this can increase processing load.

  • Layers are processed on effect creation. To re-evaluate layers each time an effect is activated, set recalculate to true.

Using Parameters

  • With recalculate: true, effects can accept parameters. For example:

[led_effect param_effect]
autostart: false
recalculate: true
leds:
    neopixel:leds
layers:
    blink {params.DURATION|default(1)|float} {params.CYCLE|default(0.5)|float} top (1.0, 0.0, 0.0)
  • To activate param_effect with custom parameters, use: SET_LED_EFFECT EFFECT=param_effect DURATION=3 CYCLE=0.2.

Setting Default Values

  • Each parameter in the layers should have a default value, as effects are initially processed without GCode context.

Last updated