[SOLVED] Could someone explain me pixel_mapper formula?

Hi guys.
I’m trying to understand pixel_mapper formula, but it seems I am dumb.

Per documentation:

display:
  - platform: addressable_light
    id: led_matrix_32x8_display
    addressable_light_id: led_matrix_32x8
    width: 32
    height: 8
    pixel_mapper: |-
      if (x % 2 == 0) {
        return (x * 8) + y;
      }
      return (x * 8) + (7 - y);
    rotation: 0°
    update_interval: 16ms

This is cool, and I’m pretty sure it is working like a charm for 32x8 matrix, which is “vertical-snake” connected, but on documentation page there is zero to nothing explanation in my opinion except this one example and I made 16x16 matrix, with data flow as on picture below:

I would be glad if someone could write correct pixel_mapper for my case at least, but I would be even more happy if someone would explain me how this is working and what are:

      if (x % 2 == 0) {
        return (x * 8) + y;
      }
      return (x * 8) + (7 - y);

so I can understand it and write my own, once when I need it again.

Many thanks in advance.

To make it more clear, in your drawing above, write down for each pixel:

  • Its X value (starting at 0)
  • Its Y value (starting at 0)
  • Its addressable number

and it will be clearer.

In your case, X=1, Y=14 should give and address of 17 i.e. (x * 16) + (15 - y)
Even rows (the % operator means modulus, or the remainder if an integer division) are just (x * 16) + Y, e.g. X=2, Y2 → adr = 34 (2* 8) + 2

Bottom-line: Replace 8 by 16 and 7 by 15 in the mapper above.

@koying : Thank you very much, you are my hero!!!

Your solution not worked out of box for me, cause this was also first thing I tried on my own, before I posted here. I mean, I supposed that numbers in formula should be 15 and 16 for my case, but just replacing 8 and 7 with 16 and 15, gave me mirrored text, which was scrolling from left to right by the way (it should scroll from right to left). But your explanation pushed me to turn brain on and I got what I wanted. Basically, x & y needs also to be switched.

Complete code for 16x16 matrix, with data flow direction as on picture above, should be:

display:
  - platform: addressable_light
    id: led_matrix_display
    addressable_light_id: mylight
    width: 16
    height: 16
    pixel_mapper: |-
      if (y % 2 == 0) {
        return (y * 16) + x;
      }
      return (y * 16) + (15 - x);
    rotation: 0°
    update_interval: 50ms

Of course:

  • For id:, one can choose any name
  • addressable_light_id: should match to ID of matrix light you want to control
  • update_interval: is optional and it setting scrolling speed
1 Like

Actually, it does :innocent:
Few examples:

1 Like

Oh, right you are, my mistake.
I will remove my bogus remark.

hello,

I have a 7x6 matrix : 7 leds width and 6 height, is someone can help for the right formula please?