PixelBlaze Snippet: Subdivision Mapping
I’ve been using the Pixel Blaze for a ‘real long time’, having met Ben at (probably) Super Con a decade ago. I’ve bought I don’t even know how many from him over the years, and given away more than I’ve used. They’re a wonderful platform for people getting started with LED Art and programming in general.
Through my professional career as an exhibit fabricator I’ve put many, …many LED strips into
projects. Something I’ve run into many times is wanting to treat individual sections of a strip as its
own. The go to here is usually plonking if/else statements all around the render function but
it’s messy, particularly when trying to move the pattern to different sections. I’ve wanted a mapper
of some sort but hadn’t found time to figure out something I like. Until now, because I need to sub-
divide a strip for a project!
The code is fairly straight forward, the map Array takes a sub Array of 3 elements,
[start, end, callback]. If an LED falls in that range, it is passed to that callback. This suites
my needs for now, but I’d like to expand it to handle non-continuous sections. And hhhheEerRrEs the code.
var map = array(3);
map[0] = [0, 10, first]
map[1] = [9, 10, second]
map[2] = [22, 10, third]
function first(i) {
hsv(1, 1, 1);
};
function second(i) {
hsv(.2, 0.5, 0.5)
}
function third(i) {
hsv(.8, 1, 1);
}
export function render(idx) {
// globalize index
index = idx;
var i = 0;
// iterate through mappings
for(; i < map.length; i++) {
var el = map[i]
// check if current index exists with this maps range
if(index > el[0] && index < el[0] + el[1]) {
// if so, call callback with normalized index
el[2](index - el[0]);
}
};
}