Pattern for Manual Control of Pixels via WebSockets?

Hello!

I’m using an external computer to fetch and manipulate data that I’d like to send to the PixelBlaze to display as one of my patterns. I’m working with a 2D strip, and externally I have a Python list of RGB tuples that’s same length as the number of LEDs representing desired LED colors.

I know I need to send the values over Websockets to an array of arrays on the PB. At what stage am I creating and setting the variable(s) needed here; In the pattern code, or via Websockets? What would the code for the pattern itself need to look like to just get the value for each LED and set the color?

Pattern Name: External Data

export var colors = array(pixelCount);
for (var i = 0; i < colors.length; i++) {
  colors[i] = array(3);
  // ?
}

export function beforeRender(delta) {
  
}

export function render(index) {
  rgb(colors[index][0], colors[index][1], colors[index][2]);
}

Hi @xd1936 ,

Unfortunately setVars doesn’t support nested arrays, so you can’t use it to set a 2 dimensional array (array of arrays) in order to structure it like you have in your pattern above.

Check out the work @zranger1 has done for an sACN proxy, which does something similar.

The idea is to pack the 3 RGB bytes into a single value and use setVars API to fill the array, then use a pattern to unpack the value back into RGB.

With some more context here

You could also use unpacked RGB values, where you create an array that is 3 * pixelCount where each pixel is 3 elements apart - similar to how a bitmap might be arranged in a byte array.

1 Like

That works!

I have my render function be:

export var pixels = array(pixelCount * 3)

export function render(index) {
  groupIndex = index * 3;
  rgb(pixels[groupIndex], pixels[groupIndex + 1], pixels[groupIndex + 2])
}

and send variables as a single-dimensional array, grouped by three. Thanks!

3 Likes

Please do share your code, we can always use more working examples.