You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Glad you got it sorted - ish :)

    When you type save() - it saves the current state of the interpreter to flash, which means if you have queued timeouts (like in your code) then those get executed.

    What I guess happens is you upload and the code actually starts running right then. You then type save() but it's actually halfway through running.

    So what you're left with is maybe only the last 2 timeouts, rather than all the timeouts as you'd expected?

    Also, would you have fiddled with the IDE and clicked Save On Send at some point in the past? This actually does what I think you're expecting - it saves your code as it was, and executes all your code on startup. It then runs onInit().

    However, if you then turn Save on Send off and upload, you're left with 2 copies of your code - what you uploaded previously and what you subsequently upload. You can run E.setBootCode() to get rid of that previous copy - but it's probably safer just to re-flash your Espruino to make sure everything is exactly as it should be.

    Also - just tried:

    function onInit(){
      setTimeout(function(){
        digitalWrite(LED1, 1);
        setTimeout(function(){
          digitalWrite(LED2, 1);
          setTimeout(function(){
            digitalWrite(LED1, 0);
            digitalWrite(LED2, 0);
          }, 1000);
        }, 1000);
      }, 1000);
    }
    

    here and it works great.

About

Avatar for Gordon @Gordon started