rpi-ws281x-native
Version:
(raspberry-pi *only*) native bindings to control a strip of WS281x-LEDs with node.js
29 lines (21 loc) • 590 B
JavaScript
var ws281x = require('../index.js');
var NUM_LEDS = parseInt(process.argv[2], 10) || 10,
pixelData = new Uint32Array(NUM_LEDS);
ws281x.init(NUM_LEDS);
// ---- trap the SIGINT and reset before exit
process.on('SIGINT', function () {
ws281x.reset();
process.nextTick(function () { process.exit(0); });
});
// ---- animation-loop
var offset = 0;
setInterval(function () {
var i=NUM_LEDS;
while(i--) {
pixelData[i] = 0;
}
pixelData[offset] = 0xffffff;
offset = (offset + 1) % NUM_LEDS;
ws281x.render(pixelData);
}, 100);
console.log('Press <ctrl>+C to exit.');