r/FastLED • Jeff Holman • May 27 '25

Support Using ScreenMap with non-standard LED layouts?

I'd love some help figuring out how to include fl::ScreenMap functionality in sketches for displays that involve something other than a super-basic LED layout.

tl/dr:

  • How can I incorporate an existing lookup table?
  • How can I implement ScreenMap with multiple data pins?

The LED panel I'm currently working with is 32x48, with six 32x8 tiles driven in pairs by 3 data pins. For each pair, the second tile is rotated 180 degrees relative to the first, like this:

[EDIT: I realized the picture below is for my 64x48 panel. My 32x48 panel has only one row of tiles.]

I've created a handful of 1D and 2D arrays that map XY coordinates to LED index number (and vice versa), which I use as lookup tables in my sketches.

I know that ScreenMap allows for the use of a lookup table, which is shown in the Fire2023 example, but I haven't figured out how to adapt that to my situation. https://github.com/FastLED/FastLED/blob/master/examples/Fire2023/Fire2023.ino

In Fire2023, it seems like the makeScreenMap() function (beginning at line 118) is *creating* a lookup table that (I assume) matches the XYTable set forth at the bottom of the sketch, but it doesn't seem that ScreenMap actually uses that XYTable in any way. Is that correct?

If so, is there a way to reference an existing lut? It seems like this would be necessary for the ScreenMap lut functionality to work with any physical LED arrangement that can't be easily mapped with a basic function like it is in Fire2023.

Here's a sketch for my 32x48 panel (stripped down for this help request) that runs two different kinds of patterns: one based on Pride (fundamentally, a 1D pattern), and one based on rainbowMatrix (a 2D pattern): https://gist.github.com/4wheeljive/30742e20c2bbed4a3784ac69ee707978

At the bottom of the sketch are two arrays with 1D and 2D mappings of my layout that correspond to the respective logic of the two pattern functions.

At various spots near the top of the sketch, I've included as comments some code that I think might, in some modified form, be used to implement the ScreenMap functionality. I would greatly appreciate any suggestions anyone might have on how to actually make this work.

Thanks!!!

5 Upvotes

14 comments sorted by

View all comments

Show parent comment

1

u/4wheeljive Jeff Holman May 31 '25

I just realized something else (I think). If I'm not mistaken, not only is fl::XYMap functionality integral to the LED output in some of the new example sketches noted above, it appears that it is also being integrated directly into some of the effects functions themselves. For example, it appears that as of several weeks ago, the old blur2d function (that could work with a user-provided XY function) has been deprecated, and blur2d now requires an XYMap mapping.

I've spent hours poring through xymap.h, xymap.cpp, vector.h, lut.h, etc., trying to find a way to inject my lookup table (i.e., my array) into XYMap. Unfortunately, I just don't understand C++ well enough (I couldn't even spell C++ a couple of weeks ago) to figure out how it all fits together. But I'm going to keep trying!

1

u/4wheeljive Jeff Holman Jun 01 '25

I did it!

I figured out how to seed fl::XYMap with the custom array for my nonstandard LED layout.

Here's the main code that got it to work (at least for a simple test sketch):

uint16_t myXYFunction(uint16_t x, uint16_t y, uint16_t width, uint16_t height) {

if (x >= width || y >= height) return 0;

return loc2indProgByRow[y][x];

}

XYMap myXYmap = XYMap::constructWithUserFunction(WIDTH, HEIGHT, myXYFunction);

loc2indProgByRow is a 32x48 array with a progressive row-by-row mapping of my layout as depicted above. It's pulled in through the mapping.h and mapping.cpp files.

The full test sketch is here: https://github.com/4wheeljive/MapTest