Skip to content

Instantly share code, notes, and snippets.

@rwaldron
Forked from twolfson/index.js
Created October 3, 2012 14:58
Show Gist options
  • Save rwaldron/3827388 to your computer and use it in GitHub Desktop.
Save rwaldron/3827388 to your computer and use it in GitHub Desktop.
Trying spaces over zeroes for led-matrix
" 11 11 ",
"1 11 1",
"1 1",
"1 1",
" 1 1 ",
" 1 1 ",
" 11 ",
" "
vs
"01100110",
"10011001",
"10000001",
"10000001",
"01000010",
"00100100",
"00011000",
"00000000"
five.LedControl.prototype.draw = function( addr, input ) {
// Arrays of strings, numbers
if ( Array.isArray(input) ) {
// Enumerate input and queue a task to write
// each "row" on nextTick
input.forEach(function( row, k ) {
// If |input| is an array of strings,
// normalize each "row" by converting
// spaces to "0". This allows users to create
// human readable "art".
// parse the string to int with a base 2 radix
if ( typeof row === "string" ) {
row = parseInt( row.replace(/ /g, "0"), 2 );
}
process.nextTick(function() {
// console.log( row );
this.row( 0, k, row );
}.bind(this));
}, this);
} else {
// TODO:
// - handling byte arrays for MATRIX CHARS
// - seven segment
// - ?
if ( LedControl.MATRIX_CHARS[ input ] ) {
this.char( addr, input /* ? */ );
}
}
return this;
};
var lc = new five.LedControl();
[
{
type: "zeros",
data: [
"01100110",
"10011001",
"10000001",
"10000001",
"01000010",
"00100100",
"00011000",
"00000000"
],
},
{
type: "spaces",
data: [
" 11 11 ",
"1 11 1",
"1 1",
"1 1",
" 1 1 ",
" 1 1 ",
" 11 ",
" "
]
}
].forEach(function( test ) {
console.log( test.type );
lc.draw( 0, test.data );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment