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.
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.
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 runsonInit()
.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 runE.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:
here and it works great.