• 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.

    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!

About

Avatar for calebbrewer @calebbrewer started