I’ve made some progress and I thought I understood the Mapping function but it’s not working for my array.
Using KITT as a test I want KITT to span the across the 4 horizontal panels then move down/up vertically.
So I modified the mapping code from the 2 example in Mapping Matrix displays Mapping matrix displays from indexing down each panel before moving to top of the next one, to index row 0 across the 4 horizontal panels then down 1 row at a time, reversing each odd row.
My code works properly for 1 8x8 panel/64 LEDs for both the map animation and the actual panel. However, when I expand the map to all the panels 4x4 panels/1024 LEDs, the animation is correct but the physical panel is just random single LEDs lighting at variuos intnesities.
I assumed with the world coordinate system I would not need to change KITT.
I have 16 8x8 panels laid out in a 4x4 square as shown above with 1024 LEDs.
panel schema
-0–1—2---3
-4–5—6---7
-8–9--10–11
12-13-14-15
8x8 LED indexing
panel:::::::0.--------1---------2--------3
scan row 0 ---------------------------->
. . .
scan row 7 <---------------------------
after row 7 go to top of panel 5 and repeat
// my version 2 - Scan across all 4 panels
//then down 1 LED row at a time//reversing for each odd row.
function (pixelCount) {
//enable zigzag if every other LED row travels in reverse
//if they are all straight across, disable it
zigzag = true
angle = 0
pxSize = pySize = 8 //panel size
panelWidth = panelHeight = 2 //num panels per direction
ylines = (panelHeight * pySize)
//roate a point (x, y), along a center (cx, cy), by an angle in degrees
function rotate(cx, cy, x, y, angle) {
var radians = (Math.PI / 180) * angle,
cos = Math.cos(radians),
sin = Math.sin(radians),
nx = (cos * (x - cx)) + (sin * (y - cy)) + cx,
ny = (cos * (y - cy)) - (sin * (x - cx)) + cy;
return [nx, ny];
}
//create a set of coordinates for a matrix panel
// sized (w, h), rotated by an angle, and offset by (sx, sy)
function panel(w, h, sx, sy, angle) {
var x, x2, y, p, map = []
y = sy //get actual y for odd/even rows //ppd
//for (y = 0; y < h; y++) { //just make ysize = 1 row
for (x = 0; x < w; x++) {
//for zigzag, flip direction every other row
if (zigzag && y % 2 == 1)
x2 = w - 1 - x
else
x2 = x
p = rotate((w-1)/2, (h-1)/2, x2, y, angle);
p[0] += sx
p[1] += sy
map.push(p)
}
// }
return map;
}
//assemble one or more panels
var map = [];
//step thru all x's in each row across all panels horizontally
//step thru y one row at a time i.e. ySize = 1
for (yOffset = 0; yOffset < ylines; yOffset++){
for (x = 0; x < panelWidth; x++){
xOffset = x * pxSize
map = map.concat(panel(pxSize, 1, xOffset, yOffset, angle))
}
}
return map
}