Using the attached as a test image with the following code, I ve got times of 1.43 seconds to fill a screen, however disabling the pin outputs the time falls down to 0.96 seconds, so I am sure more can be done to be optimized probably using assembler as the logic is actually quite simple, I expect this to be useful to someone with more skills that can improve it or changed to make it usable.
//pin B2 as B1
//pin B3 as G1
//pin B4 as R1
//pin B5 as B2
//pin B6 as G2
//pin B7 as G3
//pin B8 as clock
//pin b9 as Latch
//pin b13 as OE
var TONES=1;
console.log(getTime());
var image = require("fs").readFile("GIF/wizardcity00001.bmp", "binary");
image = image.substr(54,image.length);
var bytes = new Uint8Array(4096);
for (var j=0;j<4096;j++){
bytes[j]=Math.round(image[j].charCodeAt()*TONES/256);
}
console.log(getTime());
console.log(process.memory());
image='';
console.log(process.memory());
function rcolor(x){
return (TONES*x/256);
}
function clock(){
digitalWrite(B8,1);
digitalWrite(B8,0);
}
function latch(){
digitalWrite(B9,1);
digitalWrite(B9,0);
}
//function linea(y){
// return (y-1)*128;
//}
function linea(y){
if (y==1) {return 0;}
if (y==2) {return 128;}
if (y==3) {return 256;}
if (y==4) {return 384;}
if (y==5) {return 512;}
if (y==6) {return 640;}
if (y==7) {return 768;}
if (y==8) {return 896;}
if (y==9) {return 1024;}
if (y==10) {return 1152;}
if (y==11) {return 1280;}
if (y==12) {return 1408;}
if (y==13) {return 1536;}
if (y==14) {return 1664;}
if (y==15) {return 1792;}
if (y==16) {return 1920;}
if (y==17) {return 2048;}
if (y==18) {return 2176;}
if (y==19) {return 2304;}
if (y==20) {return 2432;}
if (y==21) {return 2560;}
if (y==22) {return 2688;}
if (y==23) {return 2816;}
if (y==24) {return 2944;}
if (y==25) {return 3072;}
if (y==26) {return 3200;}
if (y==27) {return 3328;}
if (y==28) {return 3456;}
if (y==29) {return 3584;}
if (y==30) {return 3712;}
if (y==31) {return 3840;}
if (y==32) {return 3968;}
}
function toled(){
var c=0;
var v=0;
var abcd = 0;
for (var f=0;f<TONES;f++){
for (var i=32;i>24;i--){
digitalWrite(B13,1);
abcd=32-i+1;
y=linea(i);
z=y+127;
w=linea(i-8);
x=w+127;
for (var k=y;k<z+1;k=k+4){
//if(rcolor(bytes[k])>c){
if(bytes[k]>c){
digitalWrite(B2,1);
} else {
digitalWrite(B2,0);
}
//if(rcolor(bytes[k+1])>c){
if(bytes[k+1]>c){
digitalWrite(B3,1);
} else {
digitalWrite(B3,0);
}
//if(rcolor(bytes[k+2])>c){
if(bytes[k+2]>c){
digitalWrite(B4,1);
} else {
digitalWrite(B4,0);
}
clock();
w+=4;
c+=1;
}
latch();
}
c=0;
for (var i=16;i>8;i--){
digitalWrite(B13,1);
abcd=32-i+1;
y=linea(i);
z=y+127;
w=linea(i-8);
x=w+127;
for (var k=y;k<z+1;k=k+4){
//if(rcolor(bytes[k])>c){
if(bytes[k]>c){
digitalWrite(B5,1);
} else {
digitalWrite(B5,0);
}
//if(rcolor(bytes[k+1])>c){
if(bytes[k+1]>c){
digitalWrite(B6,1);
} else {
digitalWrite(B6,0);
}
//if(rcolor(bytes[k+2])>c){
if(bytes[k+2]>c){
digitalWrite(B7,1);
} else {
digitalWrite(B7,0);
}
clock();
w+=4;
c+=1;
}
latch();
}
}
}
function onInit(){
while (digitalRead(BTN1) == 0){
var t =getTime();
toled();
console.log(' out ', t - getTime());
}
console.log(process.memory());
}
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.
Using the attached as a test image with the following code, I ve got times of 1.43 seconds to fill a screen, however disabling the pin outputs the time falls down to 0.96 seconds, so I am sure more can be done to be optimized probably using assembler as the logic is actually quite simple, I expect this to be useful to someone with more skills that can improve it or changed to make it usable.
1 Attachment