Here's code for scrolling text across a matrix

The map coordinate units can be anything. In either JSON or generated mode, the coordinates are normalized to world units (a value from 0 to just under 1.0). Your map coordinates can use integers, floats, centimeters, inches, football fields, light years, etc. The only thing that matters is the relative distance between pixels.

You shouldn’t normally need the locations (implementation details), once you save your map the interface will generally do the expected thing and load the source when you visit the mapper tab while the normalized map is used for patterns.

If you are curious, the source of your map is stored at /pixelmap.txt, and the normalized binary representation is stored at /pixelmap.dat

To use your pixel map in a pattern, implement a render2D function and export it. There are some examples in the mapper docs (scroll down on the mapper tab). Also available here.

I tried to modify mapping code from the example:

function (pixelCount) {
  width = 8
  var map = []
  for (i = 0; i < pixelCount; i++) {
    y = Math.floor(i / width)
    x = i % width
    x = y % 2 == 1 ? width - 1 - x : x //zigzag
    map.push([x, y])
  }
  return map
}

I guess, I understand every line in this code but all my attempts to modify it failed.
There was not any errors but the preview pan never looked right.
I have no idea what I was doing wrong.
I will try again carefully. I have to learn how to do this.

Also, I tried to use “Multi Panel Matrix” mapper.
Visually I got a correct results and it looked exactly as my JSON mapping looks.
The scrolling text pattern worked but up side down.
This makes no sense at all. I am scratching my head.
But it is what it is.

I never seen an example how to embed mapping code right into pattern.
@jeff provided some ideas but I am sorry, I did not get it.
It seems to be a better option because could be easier used on a different PBs.

Thank you for the info but these files are not accessible from the GUI.
I am not sure what was wrong but now I recycled power to PB and restarted browser.
Went to the “Mapper” tab and sure, I can see my mapping.

I think some screen shots would help. Are you getting an error message, or it’s just not doing what you want? What is the modified code?

The “scrolling text marquee 2D” pattern looks upright on my mapped panels. It’s possible that your map is upside down in the mapper. The multi panel mapper pattern makes it pretty easy to rotate each panel (and you can make a single one if you like). Pay special attention to the racing dots to ensure they follow the LED wiring.

If that’s still giving you trouble, this one liner will take a 2D map array and flip the y axis, add it just before the return map line:

map = map.map(([x,y]) => [x,-y])

You can even do this to your JSON map if you save it to a variable first, e.g.:

function (pixelCount) {
  var map = [
    [1,2],...
  ];
  map = map.map(([x,y]) => [x,-y])
  return map
}

If in the end you just want to flip the scrolling text pattern, you can change line 99 to this:

row = matrixRows-1-floor(y * matrixRows)

With either that or the map one liner, on my panel here the text is still scrolling from left to right, but is upside down and both cancel each other out and it’s upright again.

This isn’t something you should need to do, especially for a matrix in a fixed configuration. The pixel map describes how the pixels are physically arranged which doesn’t change (except perhaps with something like this).

The mapper type code only works on the editor on the mapper tab. However, if you really want to, you can write your own index to coordinate lookup system in a pattern and implement anything you want. To do that, you wouldn’t implement render2D or render3D, instead doing the coordinate work in a render function. Something like this:

var myMap = [
  [1,2],
  [2,3],
  //...
]

export function render(index) {
  var x = myMap[index][0]
  var y = myMap[index][1]
  //...
}

In this case your (x,y) comes from the map directly, no normalization is done and it’s in whatever units you defined.

1 Like

Today everything works as expected.
But all my yesterday’s attempts were a disaster.
Even thought, the preview window in the Mapper looked nice and clean the pattern
did not work right.
So, yesterday I ended up with creating JSON style mapping.
This was working instantly and exactly as expected.

Today I started fresh and simply replaced JSON mapping with a function
I created yesterday and even tested it with on line JAVA interpreter:

// Mapping for the 8x32 Matrix
// with vertical zigzagging
function (pixelCount)
{
  width  = 32  // Info, this value is not used
  height =  8

  var map = []

  for (i = 0; i < pixelCount; i++)
  {
    x = Math.floor(i / height) 
    y = (i % height)

    // y adjustment for vertical zigzag wiring
    y = (x % 2) == 1 ? (height - 1 - y) : y
    map.push([x, y])
  }

  return map
}

Now this is working just fine!
I wish, I new what was not right yesterday but today everything is OK.

Wow!
Thank you for the link.

Right now I have 2 PBs handy (and few more are on the way).
One is used in pretty much done project for Balcony Lighting.
This one is also integrated with Hubitat Home Automation controller.

I am playing with second PB with different LEDs configuration.
That is why the pattern embedded mapping definitely will help (I think).
So, Thank you very much for the ideas how to achieve this.

I am experienced EE (FPGA area) but now I am slowly gaining more
programming skills while playing with HE, Arduino and PB.
All these projects are 90+% are SW projects.
All related HW is basically ready to go and requires very minor
(if any at all) adjustments (soldering does not count).

For something like that, I imagine pixel count and maybe LED settings would change too, the map is similar. Though you can store a whole program (even with embedded JSON arrays) and use a variable to switch between a few saved modes by going to the editor, change a variable, and save. This way everything is there and only needs minimal manual steps to change to a different LED setup.