The issue I am facing is that it works as long as I have as blue >128 other wise something funny happens, I don't really know what, here is the full code and some sample files.
var TONES=1;
console.log(getTime());
var image = require("fs").readFile("GIF/blue.bmp", "binary");
image = image.substr(54,image.length);
if (image.length==4096){
var bytes = new Uint8Array(4096);
for (var j=0;j<4096;j++){
//bytes[j]=Math.round(image[j].charCodeAt()*TONES/256);
bytes[j]=image[j].charCodeAt();
//console.log(image[j].charCodeAt());
}
}
if (image.length==3072){
var c = 0;
var bytes = new Uint8Array(4096);
for (var j=0;j<3072;j++){
if ((c+1)%4==0){
bytes[c]=128;
c+=1;
} else {
//bytes[j]=Math.round(image[j].charCodeAt()*TONES/256);
bytes[c]=image[j].charCodeAt();
//console.log(image[j].charCodeAt());
}
c+=1;
}
}
console.log(getTime());
console.log(process.memory());
image='';
console.log(process.memory());
console.log(bytes);
function rcolor(x){
return (TONES*x/256);
}
function clock(){
digitalWrite(B8,1);
digitalWrite(B8,0);
}
function latch(){
digitalWrite([B9,B9],1);
}
//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(LED3,1);
} else {
digitalWrite(LED3,0);
}
//if(rcolor(bytes[k+1])>c){
if(bytes[k+1]>c){
digitalWrite(LED2,1);
} else {
digitalWrite(LED2,0);
}
//if(rcolor(bytes[k+2])>c){
if(bytes[k+2]>c){
digitalWrite(LED1,1);
} else {
digitalWrite(LED1,0);
}
clock();
w+=4;
c+=1;
}*/
var words = new Uint32Array(bytes.buffer,y,(z-y)/4);
//console.log(words);
[].forEach.call(words,function(col){
digitalWrite([B8,B8,B5,B6,B7],8|(((((col&0x80808000)>>15)*0x4081)>>14)&7));
console.log(col.toString(16),' - ',(col&0x80808000).toString(16));
});
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;
}*/
var words = new Uint32Array(bytes.buffer,y,(z-y)/4);
//console.log(words);
[].forEach.call(words,function(col){
digitalWrite([B8,B8,LED3,LED2,LED1],8|(((((col&0x80808000)>>15)*0x4081)>>14)&7));
console.log(col.toString(16),' - ',(col&0x80808000).toString(16));
});
latch();
}
}
}
function onInit(){
while (digitalRead(BTN1) == 0){
var t =getTime();
toled();
console.log(' sale ', 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.
Hi,
I am using this:
The data from the file comes as
The issue I am facing is that it works as long as I have as blue >128 other wise something funny happens, I don't really know what, here is the full code and some sample files.
4 Attachments