# ESPHome/Neopixelbus/WS2812 - Help with a custom lambda effect - don't understand how to adapt the code

Dear coleagues, I’m tring to achive a special addresable lamba efect. The ideea is at the opening of the garage door, the led strip should have 2 scan lights starting from the middle and travel to the end of the strips. Closing should be reveresed.

I started small, and have managed to have a scan light run from the outside till the middle of the led strip. But no mather how many things I try, I can’t reverse this yaml, so that the scan light on other half of the strip is traveling towards the middle. I have spent the half of the day tring to figure this out.

Would somebody be so kind and help me out?
I just need the scan light traveling from it.size() to it.size()/2

Thanks for your attention and time!

``````- addressable_lambda:
name: Bluescan1way
update_interval: 25ms
lambda:

static int step = 0;
static int direction = 1;

if(initial_run){
step = 0;
}

it[step] = ESPColor(0,0,255);
if(step >0 && step < it.size()/2){
it[step + (direction * -1)] = ESPColor::BLACK;
}

step = step + direction;

if(step >= it.size()/2 || step < 0){
step = 0;
it.all() = ESPColor::BLACK;
}
``````

I stumbled on this and didnt know if you got it sorted.

The light strip works by having an array of colour settings. Each position in the array represents an LED.

The original blue scan works by stepping through each ‘step’ of the light string array and setting it blue, and setting the previous 'step’s blue light back to black.

To turn on both ends of the array at the same time you need; an extra line of code to set an extra light blue

``````        it[step] = ESPColor(0,0,255);   #Turn the 'step' led blue
it[it.size() - step] = ESPColor(0,0,255);   #Turn the 'end of the strip - step' led blue
``````

and an extra line of code to set the previous extra light blue back to black.
it[step + (direction * -1)] = ESPColor::BLACK;
it[it.size() - step + direction] = ESPColor::BLACK;

``````        static int step = 0;
static int direction = 1;

if(initial_run){
step = 0;
}

it[step] = ESPColor(0,0,255);
it[it.size() - step] = ESPColor(0,0,255);
if(step >0 && step < it.size()){
it[step + (direction * -1)] = ESPColor::BLACK;
it[it.size() - step + direction] = ESPColor::BLACK;
}

step = step + direction;

if(step > it.size()/2 || step < 0){
direction = direction * -1;
step = step + (direction * 2);
}
``````

I hope that helps you work out the rest.

1 Like

Was having this project on hold, did restarted it. Your code works as expected !