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 ));
}
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.
Just a bit of magic and you have a nice collection of fireflies on an Espruino: