Clearing LEDs on strip before running a program

Very NOOB question here. I have LED strips lights (SK6812) on my roof gables under the eves. There are 3 gables so I have 6 LED strips (first pair is about 2x90 LEDs, second pair is roughly 2x41 LEDs, and the third pair is about 2x60 LEDs). So I basically have 3 channels that run off a single PB. I have my settings on the PB to only utilize 41 LEDs (since that is the smallest) with the spark-fire pattern. My problem is that when I power down and then back up, my “unlit LEDS” on the 2 (larger than 41) strips are light up carnival colors of weirdness. Its like the LEDS have memory and even thought I am not feeding data to them, them still have some kind of resident data (maybe from startup). I feel like I need a line of code that will blank out all LEDS before it starts the program.
Is there anyone else that has had this problem and found a good solution?

Hi Shark! This is a side effect of how LED strips work. They always pass the color data for each pixel down the strip like a big bucket brigade, and when the source (Pixelblaze) pauses for a few milliseconds between frames, that’s when the majority or the light our eyes will see is emitted.

So if you set Pixelblaze to think there’s 41 LEDs, the pixels past the 41st still get passed the previous pixel data. There’s some other technical details like the start frame happening in there, but for the most part, you should think of the solution like this: Configure Pixelblaze for the longest run, 90 LEDs, and edit your patterns to pass 49 “empty buckets” of “off” pixel data down the line FIRST in each frame.

That can be as simple as this code pasted right at the top within your export function render(index) { block:

if (index >= 41) { hsv(0, 0, 0); return }

Give that a try!

3 Likes

Thanks Jeff! I will give this a shot tomorrow. I am super excited to learn what I can do with the setup and I appreciate the help. I can already see some limitations in how I wired it though. Here’s a video when it runs correctly. The biggest drawback is that it doesn’t look random due to the symmetry of how I wired it. It would be really cool to get to a point where each gable side has it’s own spark-fire pattern running randomly.

2 Likes

If you rewire it in series, instead of in parallel, that’d be easy.
There aren’t a ton of LEDs, so you have 2 choices:
1 - go from one end of one to the start of the next, 5 times. Lots of wire to run.
2 - get an Output expander, and then just run whatever wires you were running to 3 of them, and wire up the other 3 (so doubling your wires, basically, back to the PB)

2 is much better, IMHO.
Then you could map the entire thing, and run not only separate sparks, but patterns across all of them.

1 Like

So I do by chance have the PB Output Expander but I am not quite following the wiring you are describing in option 2. This is how I have it wired currently:

run 3 more data lines, from A B C and remove the forks, (power is obviously fine as it is, the only thing missing is the data lines) and you’ll be all set.

The forks mean that you can ONLY do mirrored left right on each… but ideally, you want each strip independent, so you can do things like “climb up the left, go down the right, then do the next ‘hill’ and the next…”

Bare with me on this…I am super new and really appreciate the help!

I think this is what you are talking about? Just connecting data lines to the board and leave the power as is on the strips.

1 Like

Exactly so. and then set the channels for each strip.

Bingo, it’s like one big strip to PB then… you could run KITT for example, and it would glide along your house.

If you want 6 sparks, we have a few ways to do that… the easiest is the multi segment pattern (we might need to add spark to it, if it’s not an option to pick yet). Some patterns are easiest to adapt than others.

I haven’t given up on this project, I just haven’t received my PB that I ordered. For some reason it is taking a really long time. I will be back once I get it.

Okay, new PB came in the mail (this will be my designated test board so I can have something for halloween if all esle fails). I wired up 3 strips of LEDs just like the ones on the house that have 50 LEDs each. The wiring is done the same as described above and it all works as expected. I did notice one limitation (maybe it can be fixed in code someday when I learn how) due to the way i have it wired. The direction of data to each strip always starts at the bottom of the roof line and moves up to the peak. If i do the KITT program, the light progresses up one strand to the apex and then the next strand starts at the base and progresses up to the apex. So it will not look continuous. I think I have either re-wire data in series (which will be a major PIA ) or figure out some code “switch”. Maybe I am overlooking something. Anyone have suggestions?

You are overlooking mapping.

Yes, if you just run from left to right, it’ll climb 6 times. But the map will allow you to light up(for example), starting at the bottom of each all at once, or going along, up and then down, etc.

This is why we recommend mapping and not mirroring. You can do anything with a map.

To be clearer: yes, things which run mapless, just using index won’t behave the way you want (like it was 3 big strings going up and back down), BUT there is a very easy hack you can add to those to make them do so.

Hint: if index is between A and B where you want it to run from B to A instead, then you cheat it.
For example: string goes from 0-49 up, and then from 50-99 also up, but you want it to look like it will do 99 to 50 (aka down)?

Index = index-50 (so now index is 0-49, right?)
Index = 49-index (so now index is 49-0, right?)
Index = Index + 50 (now index is 99-50, see?)

On one line:

if (index >= 50 && index <= 99) {index = 50 - index + 99 }

(and yes, replace 50 and 99 with whatever the ends are, and you can do more than one of these, you’ll want three in your case)

1 Like

I sort of see what you are saying, i just can’t figure out where i put the code. I looked at the mapper and tried to understand how it gets implemented but couldn’t figure it out. I also looked in the KITT code, but not sure where it would go there. Sorry I am such a novice. Is there some kind of example code i could look at to see how the index variable works?

I found a good intro to the programming I missed earlier while trying to edit the first pattern. I looks like it talks about index in there so I will go through that first. Right now just learning how to comment out code. Yay. I made my LEDs purple by commenting out code. Seriously though, glad whoever wrote it spent the time to help people like me to start from scratch.

2 Likes

No apologies needed. We all start somewhere.

Yes, learn how the basics work, and you’ll grow from there.

In the render() function, index is used as the value of whatever pixel is being rendered.

That’s what render(index) means

So putting the line above at the very start of that function will change the value of the index for that particular pixel. So when pixel #50 would be rendered, that line would change the index number to be 99… And so on.

I tried using it at the begining of this render function but I think i am missing something because it gives me an unexpected identifier error.

Let’s try turning on the third pixel and we’ll make it green.
*/

export function render(index) {

  • if (index is >= 50 && index <= 99) {index = 50 - index + 99 }*
  • if (index == 48) { // index 2 is the third pixel*
  • rgb(0, 1, 0) // Red is zero (off), green is 1 (full on), blue is 0*
  • } else {*
  • rgb(0, 0, 0) // If the index is NOT equal to 2, all 3 colors are off*
  • }*
    }

Edit the above, please.

Paste your code, then highlight and click the button next to the quotes, the </>

export function render(index) {
   if (index is >= 50 && index <= 99) {index = 50 - index + 99 }
  if (index == 4) {  // index 2 is the third pixel
   
    rgb(0, 1, 0)     // Red is zero (off), green is 1 (full on), blue is 0
  } else {
    rgb(0, 0, 0)     // If the index is NOT equal to 2, all 3 colors are off
  }
}

Oh my bad.

Remove the Is. I did that code on my phone, from scratch and should have caught that when I turned it into a single line of code

Holy Fballs iT WORKS!
Now im going to try to see if I can light up the first light of the third strand…this is fun

1 Like

Scruffy thank you very much! I really appreciate you taking the time out of your day to help out. You would have thought someone scored a touchdown in my kitchen as soon as i saw the red leds dancing along. Im sure it is pretty insignificant to you but I can assure you I feel like a 4 year old who just took off the training wheels! So now that I’ve got the KITT pattern snaking up and down the 3 strips on my countertop I am now trying to solidify my understanding of what is really taking place. I am curious about the line of code that makes this all work. I think I only grasp 50% of what is going on. When I read the following:

if (index >= 50 && index <= 99) {index = 50 - index + 99 }

I (probably incorrectly) interpret it as saying " if index is greater than or equal to 50 BUT less than or equal to 99, THEN set index to (50 - index + 99)"

and this is where my understanding of how all this works has me scratching my head. When the function is called does it run through the function with index starting at 0 and then rerunning it with 1 …etc etc until 150 and then start over at 0 again? All of this happening at the clock speed of the chip or whatever?

uh maybe i only understand 10% of what is going on