Thought I'd give the Matrix a try by porting over code from the gamer library here, which has been converted to:
var OE = B6;
var CLK1 = C6;
var CLK2 = C7;
var DAT = C8;
var LAT = C9;
var HIGH = 1;
var LOW = 0;
pinMode(OE, 'output');
pinMode(CLK1, 'output');
pinMode(CLK2, 'output');
pinMode(DAT, 'output');
pinMode(LAT, 'output');
var counter = 0;
var currentRow = 0;
var image = new Uint8Array(8);
var display = [
[1,1,1,1,1,1,1,1],
[1,1,1,1,1,1,1,1],
[1,1,0,0,0,0,0,0],
[1,1,1,1,1,1,1,1],
[1,1,1,1,1,1,1,1],
[1,1,0,0,0,0,0,0],
[1,1,1,1,1,1,1,1],
[1,1,1,1,1,1,1,1]
];
function updateDisplay()
{
var newImg = new Uint8Array(8);
for(var j=0; j<8; j++) {
newImg[j] = 0x00;
for(var i=0; i<8; i++) {
newImg[j] <<= 1;
newImg[j] |= display[j][i];
}
}
if(newImg != image) {
for(var i=0; i<8; i++){
image[i] = newImg[i];
}
}
}
function updateRow()
{
if(counter==8) {
counter = 0;
currentRow = 0x80;
}
writeToRegister(0);
writeToDriver(image[counter]);
writeToRegister(currentRow);
currentRow >>= 1;
counter++;
}
function writeToDriver(dataOut)
{
//console.log("Driver data:" + dataOut);
digitalWrite(OE, HIGH);
for(var x=0; x<=7; x++) {
digitalWrite(CLK1, LOW);
digitalWrite(DAT, (dataOut & (1<<x)) >> x);
digitalWrite(CLK1, HIGH);
}
digitalWrite(LAT, HIGH);
digitalWrite(LAT, LOW);
digitalWrite(OE, LOW);
}
function writeToRegister(dataOut)
{
//console.log("Register data:" + dataOut);
digitalWrite(LAT, LOW);
for(var y=0; y<=7; y++) {
digitalWrite(DAT, (dataOut & (1<<y)) >> y);
digitalWrite(CLK2, HIGH);
digitalWrite(CLK2, LOW);
}
digitalWrite(LAT, HIGH);
digitalWrite(LAT, LOW);
}
updateDisplay();
setInterval(function(){
updateRow();
}, 1);
And it actually works, to a degree :) Right now, because it's using a bitshifter to update the LED rows one at a time, it seems the Espruino isn't firing quick enough to make it look seemless.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Thought I'd give the Matrix a try by porting over code from the gamer library here, which has been converted to:
And it actually works, to a degree :) Right now, because it's using a bitshifter to update the LED rows one at a time, it seems the Espruino isn't firing quick enough to make it look seemless.
http://t.co/B9q0BoKey2
Is there anything that can be done to speed this up? or can anyone suggest any alternative way of updating the display in one burst?
Many thanks
Matt