I have built a custom LED matrix consisting of 5 modules, each with an 8x8 LED grid, resulting in a total resolution of 8x40 (height x width). I wrote a test script that displays squares on the matrix. This test confirms that the physical positions of the modules and the pixel mapping are accurate.
light:
- platform: neopixelbus
id: led_matrix_light
type: GRB
variant: WS2811
pin: GPIO4
num_leds: 320
name: "NeoPixel Light"
color_correct: [20%, 20%, 20%]
display:
- platform: addressable_light
id: led_matrix_display
addressable_light_id: led_matrix_light
width: 40
height: 8
pixel_mapper: |-
if (x / 8 % 2 == 0) {
return x * 8 + y;
}
return (x + 1) * 8 - y - 1;
rotation: 0°
update_interval: 16ms
lambda: |-
// Draw a pattern for 40x8 matrix
Color red = Color(0xFF0000);
Color green = Color(0x00FF00);
Color blue = Color(0x0000FF);
it.rectangle(0, 0, 40, 8, red); // Full outer rectangle
it.rectangle(4, 1, 32, 6, green); // Inner rectangle
it.rectangle(8, 2, 24, 4, blue); // Smaller inner rectangle
it.rectangle(12, 3, 16, 2, red); // Smallest inner rectangle
font:
- file: "fonts/PixelOperatorMono8.ttf"
id: my_font
size: 8
When I modified the code to display text instead of squares, something unexpected happened. The test was to display the text “aaaaa” across the matrix. However, I noticed that the first, third, and fifth “a” were flipped vertically, while the second and fourth “a” displayed correctly.
Can you believe it? It seems like there’s an issue with how the text is being mapped or rendered on the matrix.
lambda: |-
it.fill(Color(0x000000));
it.print(0, 0, id(my_font), Color(0xFFFFFF), TextAlign::TOP_LEFT, "aaaaa");