Replying to my own post just to say timer.js works nicely. Install it with “npm install --save-dev timer.js” and then use a tick event on a timer. Ticking every 5ms seems to work nicely, but 1ms still sees some leds not lighting correctly. I can live with that. Sharing the code as I go… (ticks are every 0.1 seconds (100ms) in this version).
var blinkstick = require('blinkstick');
var Timer = require('timer.js');
var leds = blinkstick.findFirst();
var x = 0;
var v = 1;
var color = 'red';
var k = new Timer({
tick : 0.1,
ontick : function(sec) {
leds.setColor(color, { index: x });
x = x + v;
if (x === 9) { x = 8; v = -1; color = 'black'; }
if (x === -1) { x = 0; v = 1; color = 'red'; }
},
onend : function() {
c('black',0);
}
});
k.start(5);
function c(color, x){
if (x > 8) { return; }
leds.setColor(color, { index: x }, function(err){
x++;
c(color, x);
});
}
You must allow about 30 ms before you send another color to a single LED or you can use LED frames to light up all connected LEDs at once, but the same 30ms rule still applies. This is required, because BlinkStick can’t communicate via USB when it’s sending data to LEDs and 30 ms is the safe amount of time for BlinkStick to complete the data transfer to LEDs.