Don't worry about formatting, just type in the text and we'll take care of making sense of it. We will auto-convert links, and if you put asterisks around words we will make them bold.
Tips:
For a full reference visit the Markdown syntax.
Posted by
@allObjects
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.
This tutorial was triggered by the forum post about code not running after save() and power cycle and related response, which states:
Conclusion and recommendation: ...indeed... therefore, always choose the format that works for/after
save()
... to be on the safe side.But this is a bit cumbersome while developing, because you need to save the uploaded code every time and do a power-cycle - un-plug and re-plug - to get the code started. To get around this and speed up development, use this stream lined development process.
function onInit() { ... }
rather thanE.on('init', function(){ ... });
, and start your code after uploading by enteringonInit()
in the console / left hand pane of the Espruino Web IDE.Having to enter
onInit()
in the console every time after upload of the code to start it is still somewhat cumbersome, thereforeAdd - for development time -
setTimeout(onInit,500);
as last line in your code, which makes your overall code structure look like this:This last line starts your code automatically after upload has completed in the same way as later on a power cycle will restart it on normal runtime after power cycle / reset. The timeout is added to allow - on the Espruino side - the upload process to complete and do so decoupled from your code start / execution.
setTimeout(onInit,500);
when entering the final development phase where you testsave()
and power-cycling.Bonus for using
setTimeout(onInit, ...
:You can pass development time parameters
that overwrite runtime parameters - for example for debugging w/ console output while developing - which automatically go away for the normal runtime. Your overall code may then look something like this complete code template good for code running after both direct upload AND save() :
Code Template for development AND runtime: