Skip to content

Instantly share code, notes, and snippets.

@ajfisher ajfisher/matrix.js
Created Jul 30, 2016

Embed
What would you like to do?
Dirty version of mbot LED matrix working with johnny-five
var five = require("johnny-five");
var board = five.Board();
//Define Data Command Parameters
var Mode_Address_Auto_Add_1 = 0x40 //0100 0000 B
var Mode_Permanent_Address = 0x44 //0100 0100 B
board.on("ready", function() {
var sck = five.Pin({
pin: 14,
mode: this.io.MODES.OUTPUT,
});
var din = five.Pin({
pin: 15,
mode: this.io.MODES.OUTPUT,
});
console.log("board ready");
// sets mode
writeByte(sck, din, 0x40);
// set brightness
writeByte(sck, din, 0x8C);
clearScreen(sck, din)
var value = 0;
//var buff = new Buffer([0xFF, 0x7E, 0x3C, 0x18, 0x18, 0x3C, 0x7E, 0xFF, 0xFF, 0x7E, 0x3C, 0x18, 0x18, 0x3C, 0x7E, 0xFF]);
var buff = new Buffer([0xFF, 0x0F, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
writeBytesToAddress(sck, din, 0, buff);
// setInterval(function() {
// var ml = 16;
// var tempBuff = new Buffer(ml);
// buff.copy(tempBuff, 0, 1);
// tempBuff[ml-1] = buff[0];
// //console.log(tempBuff);
// buff = tempBuff;
// writeBytesToAddress(sck, din, 0, buff);
// }.bind(this), 1000/15);
});
function clearScreen(sck, din) {
var buff = new Buffer(16);
buff.fill(0x00);
writeBytesToAddress(sck, din, 0, buff);
}
function writeByte (sck, din, data) {
// start
sck.high();
din.low();
for (i=0; i<8; i++) {
sck.low();
din.write(data & 0x01);
sck.high();
data = data >> 1;
}
// end
sck.low();
din.low();
sck.high();
din.high();
}
function writeBytesToAddress (sck, din, address, data) {
// data is a buffer
address = address | 0xC0;
// start
sck.high();
din.low();
for (i=0; i<8; i++) {
sck.low();
din.write(address & 0x01);
sck.high();
address = address >> 1;
}
for (k=0; k<data.length; k++) {
var d = data[k];
for (i=0; i<8; i++) {
sck.low();
din.write(d & 0x01);
sck.high();
d = d >> 1;
}
}
// end
sck.low();
din.low();
sck.high();
din.high();
}
@geekscape

This comment has been minimized.

Copy link

geekscape commented Jul 30, 2016

Thanks @ajfisher, I've added more functionality ... https://gist.github.com/geekscape/8e7e949c7e610c46ebfebad50c9ed9de

Now has the concept of a "screen", which you can clear, invert, draw points, lines (horizontal, vertical and other), rectangles (draw and fill) and circles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.