When I try to change a pin's mode inside a setInterval after a number of loops Espruino hangs. For example:
var count = 0; const onInit = () => { var loop = setInterval(() => { if (count === 1000) { digitalWrite(1, 0); } console.log('foo', count); count = count + 1; }, 5); setTimeout(function() { clearInterval(loop); console.log("foobar"); }, 10000); }; setTimeout(onInit, 1000);
It will turn the pin off and log foo 999. It will never log foobar.
foo 999
foobar
The odd thing is that I can create a blink loop with setInterval like this:
var state = 0; const onInit = () => { var loop = setInterval(() => { digitalWrite(1, state); console.log('foo', state); state = !state; }, 500); }; setTimeout(onInit, 1000);
Any help would be great!
@calebbrewer 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.
When I try to change a pin's mode inside a setInterval after a number of loops Espruino hangs.
For example:
It will turn the pin off and log
foo 999
. It will never logfoobar
.The odd thing is that I can create a blink loop with setInterval like this:
Any help would be great!