Skip to content

Commit f5856f7

Browse files
author
Martin Schuhfuss
committed
add new example that just iterates through all leds
1 parent e7c10e2 commit f5856f7

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

examples/iterate.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
var ws281x = require('../index.js');
2+
3+
var NUM_LEDS = parseInt(process.argv[2], 10) || 10,
4+
pixelData = new Uint32Array(NUM_LEDS);
5+
6+
ws281x.init(NUM_LEDS);
7+
8+
ws281x.setIndexMapping(ws281x.indexMapping.mirrorMatrixX(10,10));
9+
10+
// ---- trap the SIGINT and reset before exit
11+
process.on('SIGINT', function () {
12+
ws281x.reset();
13+
process.nextTick(function () { process.exit(0); });
14+
});
15+
16+
17+
// ---- animation-loop
18+
var offset = 0;
19+
setInterval(function () {
20+
var i=NUM_LEDS;
21+
while(i--) {
22+
pixelData[i] = 0;
23+
}
24+
pixelData[offset] = 0xffffff;
25+
26+
offset = (offset + 1) % NUM_LEDS;
27+
ws281x.render(pixelData);
28+
}, 100);
29+
30+
console.log('Press <ctrl>+C to exit.');

0 commit comments

Comments
 (0)