setTimeout seems to be terribly broken (I could not get it working at all)
code sent from the IDE (to RAM) should not be started immediately after uploading (the IDE seems to expect some response from the connected device which it might not receive otherwise). But you will have to use setInterval for that purpose (as setTimeout is broken, see above)
the graphics library also seems to have its problems (drawString seems to work fine, but drawLine seems to be flaky)
My updated code
function currentXYZ () {
return [2,0,5];
}
var Buffer;
function drawBar (x,Length) {
for (var i = 0; i <= Length; i++) {
var Bit = x+(4-i)*5;
Buffer = Buffer | (1 << Bit);
}
}
function updateDisplay () {
var XYZ = currentXYZ();
Buffer = 0;
drawBar(0,Math.max(0,Math.min(4,XYZ[0])));
drawBar(2,Math.max(0,Math.min(4,XYZ[1])));
drawBar(4,Math.max(0,Math.min(4,XYZ[2])));
show(Buffer);
}
setInterval(updateDisplay,100);
runs fine for much longer now than any other variant did.
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.
My conclusions so far:
setTimeout
seems to be terribly broken (I could not get it working at all)setInterval
for that purpose (assetTimeout
is broken, see above)drawString
seems to work fine, butdrawLine
seems to be flaky)My updated code
runs fine for much longer now than any other variant did.
With greetings from Germany,
Andreas Rozek