Continuous circular snake pattern

Hello, I’m new to PixelBlaze and I’m working on a project where I have a ring of 4 RGBW LED strips I want to run a continuous snake pattern on. Basically I want the lights to be chasing themselves continuously a circle. I’m using the PixelBlaze XL and the Expander Pro. This code was working quite well when I had a single strip attached. Its the modified “Snake” code which I set to just run with the white diode.

distance = 50

export function beforeRender(delta) {
  t1 = time(.4)
}

export function render(index) {
  h = 0
  s = 0
  v = 1
  
  head = t1 * pixelCount
  offset = (head - index + pixelCount) % pixelCount
  
  hsv(h, s, clamp(1 - offset / distance, 0, 1))
}

The issue is when I attached the other 3 it created a time gap after it runs the full animation. I’m curious if anyone can help me troubleshoot how to get rid of that time gap between animations while running all 4 strips. I currently have each strip attached to its own terminal block and the the data wires are attached to D0, D2, D4 and D6. In the PixelBlaze settings I have the start index for each set to 0 and the pixel number set to 100 (the number of pixels in each strip).

Any help would be greatly appreciated.

I was able to make it work by just connecting all the data wires to D0. That made it so there is no gap between the animations, making it look pretty seamless. That said, I’m still curious how to do this by using 4 different data lines since it would help make the wiring a lot cleaner.

I think the trick here is that if you overlap indexes with an output expander, the pixelCount still increases, even though they won’t have their own index. When your pattern code uses pixelCount, it’s running as if there were a lot more pixels than what you can see.

Using another variable instead of pixelCount, and setting that to the number of pixels with an index would probably do the trick. Sharing the data output is totally fine too.

Ah yeah that makes a lot of sense. I changed “pixelCount” to 100 (number of pixels on each strip) and now its working as expected. Thanks for the help!

The new code look like this:

distance = 50

export function beforeRender(delta) {
  t1 = time(.16)
}

export function render(index) {
  h = 0
  s = 0
  v = 1
  
  head = t1 * 100
  offset = (head - index + 100) % 100
  
  hsv(h, s, clamp(1 - offset / distance, 0, 1))
}
1 Like