• In general why would code execute during a upload/copy process?

    http://www.espruino.com/Saving

    Why should the Neopixels be activated during the 'upload' process?

    // random colours
    var arr = new Uint8ClampedArray(25*3);
    var n = 0;
    for(var i=0;i<25;i++) {
      arr[n++] = Math.random()*255;
      arr[n++] = Math.random()*255;
      arr[n++] = Math.random()*255;
    //}
    require("neopixel").write(B15, arr);
    //delay();
    }
    

    That's not actually the code from http://www.espruino.com/WS2811 - you added the require("neopixel").write(B15, arr); inside the loop - so it's outputting 25x the 25 LED strip, and is doing so during the upload process.

    Normally what you might do is:

    function onTimer() {
      var arr = new Uint8ClampedArray(25*3);
      var n = 0;
      for(var i=0;i<25;i++) {
        arr[n++] = Math.random()*255;
        arr[n++] = Math.random()*255;
        arr[n++] = Math.random()*255;
      }
      require("neopixel").write(B15, arr);
    }
    
    setInterval(onTimer,100);
    

    Where the only command that's actually executed is setInterval.

    Am I to understand that when using the upload button press process for right hand pane code locks, that code is already executing before the upload is complete and before E.init is detected?

    Yes - by default. Check out the Saving link above - there's a bit of explanation in there. If you upload all at once and then execute you need twice as much memory as you need the original program text, plus the 'parsed' version of all the functions.

    Isn't that what the E.init entry point is for, making sure that nothing else executes before the init() function?

    Yes, that's why you should put the code you want to execute at startup inside it rather than in the body of your code :)

About

Avatar for Gordon @Gordon started