Thanks Gordon! mapInPlace sure is much faster. Here's my fade code with callback:
function fade(b, direction, callback) { var m = 1; var clone = new Uint8Array(b.length); clone.set(b); var interval = setInterval(function () { if(direction===0){ E.mapInPlace(b, clone, function (x) { return x * m; }); }else{ E.mapInPlace(b, clone, function (x) { return x - (x * m); }); } m *= direction===0?0.85:0.95; leds.buffer = clone; leds.flip(); if (m <= (direction===0?0.01:0.1)) { clearInterval(interval); if (callback) { callback(); } E.mapInPlace(b, clone, function (x) { return direction===0?0:x; }); leds.buffer = clone; leds.flip(); } }, 10); }
@n00b started
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.
Thanks Gordon! mapInPlace sure is much faster. Here's my fade code with callback: