I think the issue is your use of clearInterval(); in setLed - this will clear ALL intervals, including the one calling readBatt. So in reality readBatt will only get called once.
You probably want:
var flashInterval;
function setLed() {
if (flashInterval) clearInterval(flashInterval);
if(v < 3) {
flashInterval = setInterval("digitalPulse(D1, 0, [200,50,100,50]);", 10000);
} else {
flashInterval = setInterval("digitalPulse(D1, 0, [200,50]);", 10000);
}
}
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.
I think the issue is your use of
clearInterval();
insetLed
- this will clear ALL intervals, including the one callingreadBatt
. So in realityreadBatt
will only get called once.You probably want: