Chase effect for Neopixels?

I wonder if anyone can guide me on how I could create a “chase” effect on an ESPHome device connected to a small string of 50 WS2812 neopixels.

Forums, Google and AI guided me to a lambda approach but I’m having issues with the correct syntax.

I appreciate AI solutions are not recommended but it’s one of the tools in our belt and this is what I have so far which does not compile…

- lambda:
          name: "Chase Effect"
          update_interval: 100ms
          lambda: |-
            static int pos = 0;
            auto& strip = id(neopixel_strip);
            strip->clear();
            strip[pos].set_rgb(1.0, 0.0, 0.0);
            strip->update();
            pos = (pos + 1) % 50;

The inbuilt Rainbow one kinda achieves what I’d like but I’d like to hard code the colour, the direction left vs right and also the speed… My goal is to show the status of my solar battery depending on if it’s charging/discharging and also hopefully the rate.

1 Like