Skip to content

Instantly share code, notes, and snippets.

@mattdesl
Created November 21, 2017 16:36
Show Gist options
  • Save mattdesl/7e075159e768edc7a4a46d3981c2e7ce to your computer and use it in GitHub Desktop.
Save mattdesl/7e075159e768edc7a4a46d3981c2e7ce to your computer and use it in GitHub Desktop.

Some really rough/hacky code that remaps 6 32x32 LED panels to a 96x96 size triangle (3 panels on bottom row, 2 on middle row, and 1 panel on top row).

The order of wiring is specific and unusual, in order to support smaller IDC cable lengths. The IDC ribbon starts with the PI at the bottom right panel, snakes along to the left, then up to the left panel of the second row, snaking right and up to the top row.

The two panels in the middle row are placed upside-down.

img

Use --led-chain=6 when running.

Tested with Adafruit HAT (PWM mod) and 6 Adafruit 5mm pitch 32x32 LED matrix panels. https://github.com/hzeller/rpi-rgb-led-matrix/

bool remapPixels (int& x, int& y) {
int width = LED_PIXELS_WIDTH;
int height = LED_PIXELS_HEIGHT;
// now we remap this pixel to the new space
int nx = x;
int ny = y;
// find out which row we are on
int row;
if (y >= 0 && y < 32) row = 0;
else if (y >= 32 && y < 64) row = 1;
else if (y >= 64 && y < 96) row = 2;
else return false;
if (row == 0) {
// outside of top row bounds
if (x < 32 || x >= 64) return false;
// center top row of pixels
nx -= 32;
} else if (row == 1) {
// outside of middle row bounds
if (x < 16 || x >= 80) return false;
// remap the Y value to the single row format
ny -= 32;
if (x >= 16 && x < 48) {
// middle row, left panel...
// third panel in the chain
// remove border
nx -= 16;
// now offset & flip horizontally to correct position
nx = 64 + (32 - nx - 1);
} else {
// don't need to do anything here,
// srcX = (48..80) - border = 32..64
// dstX = 32..64
// remove border
nx -= 16;
// remove first panel
nx -= 32;
// offset and flip
nx = 32 + (32 - nx - 1);
}
// flip the Y value
ny = 32 - ny - 1;
} else {
// outside of bounds
if (x < 0 || x >= 96) return false;
// remap Y value to single row
ny -= 64;
// move to last 3 panels
nx += (3 * 32);
}
// apply remap
x = nx;
y = ny;
return true;
}
// ... in Run() ...
// ...
int width = 96;
int height = 96;
for (int i = 0; i < width * height; i++) {
int x = i % width;
int y = i / width;
int nx = x;
int ny = y;
if (remapPixels(nx, ny)) {
// do some operations on the original pixel coordinate
// to get a new RGB value
int r, g, b;
pixelShader(x, y, width, height, r, g, b);
// set this pixel color at the new pixel coordinate
canvas()->SetPixel(nx, ny, r, g, b);
}
}
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment