Read a Data Series - Control LEDs in a Matrix

Also, I ran the code you posted, with the 500 item data set from a few messages up. On my PB2, with a 16x16 WS2812 matrix (256 pixels), it runs at a fairly constant 87 fps. This is about what I’d expect. Is yours still running slowly?

Edit: Oh – just realized, you probably need to change the LED type in your PB’s settings to “Buffered (x2 rate) WS2812/Neopixel”. This greatly helps performance as the number of pixels goes up!

1 Like

@jeff This one is straight-forward. Very simple. Very nice. In this case the array is just a container for data. Thanks.

Quote=“jeff, post:13, topic:1055”]

Populating an array’s values manually

Let’s just work with the first 5 of your pixels for this one.

export var data = array(5) // Set up a 5-bin container

[/quote]

On the other hand,

gave me a “fract” unrecognized error. (Displays a nice rainbow, tho) so I modified the code - But it does not work…

var brightnesses = array(pixelCount)
var saturation = array(pixelCount)
export var brightnesses // Watcher
export var saturation // Watcher

for (i = 0; i < pixelCount; i++) {

if (sqrt((i) -floor (i)) == 0) {    // "if (frac(sqrt(i)) == 0) { > unrecognized, 
                                    // so re-wrote. But it does not work.
  
brightnesses[i] = 0.2 
  saturation[i] = 1  
}

else {

brightnesses[i] = 0
saturation[i] = 0      

}
}

export function render(index) {
h = 0 // Red for easy diagnostics - index/pixelCount = Rainbow
s = saturation[index]
v = brightnesses[index]

hsv(h, s, v)
}
Getting there with arrays. They are a many splendored thing!

Yes! Super nice. Great for defining a range. But, what if, for example, index < DATA_SIZE (which it seems to be).

This sped things up to about 90 FPS.
But then, why and when to use buffering and why not use it always. Perhaps just as you say, “improves performance as the number of pixels goes up.”

Side Note: I had messed with data speed but that just blanked everything! Didn’t think to change the pixel type.

Thanks!

My mistake - frac() is only available on v3.

Something equivalent on v2 is:

if (floor(sqrt(i)) == sqrt(i)) {

No problem, there’s lots to keep track of! Glad we got it sorted-out.

So, for really big arrays could we feed the values into PB from a websocket or some other off-board vehicle? Asking for a friend

Yes, you can feed in as much data as you like through the websockets API. Take a look at this thread for an example that sends about 1k of data per frame at a rate of 20fps :

That IS awesome!

So I am on the right page, a “frame” is one full render of the index, yes?

Question: About how much data would be required to send over one three digit number and one four digit number?

I know… so many questions???

Each digit is an byte (could be less, depends on what you’re doing…)

So call it 7bytes of data? Tiny.

Cool! Tiny is good. I’ve got two pretty long strings of basically parallel data to work with so I’m running up against what I understand is a 20,000 character limit in PB-code space. Not sure if this is carried over to the v3. Thus looking at running it in through a websocket.