You are reading a single comment by @Kim and its replies. Click here to read the full conversation.
  • Just a bit of magic and you have a nice collection of fireflies on an Espruino:

    function createFireFly(milliseconds) {
      milliseconds = ((typeof milliseconds) === "undefined") ? 0 : milliseconds;
      setTimeout(function() {
        var led;
        var next = Math.random();
        if (next <= 0.05) {
          led = LED1;
        } else if (next <= 0.1) {
          led = LED3;
        } else {
          led = LED2;
        }
        var duration = 1000 + Math.random() * 2000;
        led.glow(duration);
        createFireFly(duration);
      // activate the new firefly after the current one is done, 
      // with an added delay of at most 1 second
      // though every so often ... it may take a bit longer
      }, milliseconds + Math.random() * 2000 + (Math.random() < 0.01 ? 5000 + Math.random() * 10000 : 0 ));
    }
    
About

Avatar for Kim @Kim started