• Your issue is that all your code runs within the upload cycle and that messes most of the time with the actual upload and things just do not what they should do.

    Simplest thing, put your doStart() into the onInit(){} function. After upload, you enter onInit() in the console and your code will either just work straight from the start or reveal issues it has. For convenience while you get the code to get its act together and not having to type into the console for starting it after every upload, add this as a last line - which you remove for final upload for save():

    setTimeout(onInit,999); // while dev'ing; remove before upload for save()
    

    Adding the onInit(){...} gives you two birds w/ one stone:

    1. You get out of the bind that upload and execution bite/fight each other
    2. Your code will start automatically cleanly on each power cycle

    PS: JS is executed while uploaded. For the last thing you have doStart() which sets everything in motion before the upload has completed (except you have save on send checked in the IDE... which is not the point of (original) Espruino... it was first added to help to overcome Arduinism, and later, to increase memory saving by writing things directly into Flash and execute (most of) it from there.

  • Thank you for your help! It's the first time I code for Espruino and I still need to get used to it. I had concern about the loop functions, since I thought that the way they work is quite different from the environment I used to work in (especially Arduino). I will try to change my code according to your suggestions, thank you!

About

Avatar for user109290 @user109290 started