Hi,
can someone review my code? i think that there must be a more efficient way to get this done.
console.log("start"); //595 Belegung: /* 1 = 2 2 = 3 3 = 4 4 = 5 5 = 6 6 = 7 7 = 8 = Decimal Point, not used 8 = GND 9 = Serial Out, not used 10 = CLR Rest, Pin B7 11 = SCK, SPI1 SCK, Pin B3 12 = SS/RCK,Pin B6, 10KOhm to GND 13 = Output Enable, GND 14 = Datum/SER/SIN, SPI1 MOSI, Pin B5 15 = 1 16 = VCC 3,3V + 330Ohm */ //SS Pin = B6 //reset=B7 //B10 1000 - 9999 //B13 100 - 999 //B14 10 - 99 //B15 0 - 9 var one = 48; // "00110000"; var two = 91; // "01011001"; var three = 121; // "01111001"; var four = 116; // "01110100"; var five = 109; // "01101101"; var six = 111; // "01101111"; var seven = 56; // "00111000"; var eight = 127; // "01111111"; var nine = 125; // "01111101"; var zero = 63; // "00111111"; var z = [zero,one,two,three,four,five,six,seven,eight,nine]; var outpins = [B10,B13,B14,B15]; // the four 7 Segment LED Blocks digitalWrite(outpins,15); // LEDs off 15=1111 digitalWrite([B7,B6],0); // SS Pin und Reset to 0 digitalWrite([B7],1); // Reset to 1 pinMode(B10, output); pinMode(B13, output); pinMode(B14, output); pinMode(B15, output); SPI1.setup({ mosi:B5, sck:B3, baud:4000000 }); //SPI Setup var out = 0; // current Segment var i = 0; // Counter var i1=0, i2=0, i3=0, i4=0; //increase counter and split setInterval(function(){ i++; if (i>9999)i=0; if (i>999){ i1 = Math.floor(i/1000); } else { i1 = 0; } if (i>99){ i2 = Math.floor(i/100) % 10; } else { i2 = 0; } if (i>9){ i3 = Math.floor(i/10) % 10; } else { i3 = 0; } i4 = i % 10; },10); function loop4() { SPI1.send(z[i1],B6); digitalPulse(outpins[0],0,4); setTimeout(loop3,4); } function loop3() { SPI1.send(z[i2],B6); digitalPulse(outpins[1],0,4); setTimeout(loop2,4); } function loop2() { SPI1.send(z[i3],B6); digitalPulse(outpins[2],0,4); setTimeout(loop1,4); } function loop1() { SPI1.send(z[i4],B6); digitalPulse(outpins[3],0,4); setTimeout(loop4,4); } loop4();
2 Attachments
@werty1st started
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,
can someone review my code? i think that there must be a more efficient way to get this done.
2 Attachments