forked from ch2i/LoraGW-Setup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testled.js
executable file
·46 lines (35 loc) · 854 Bytes
/
testled.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env node
var ws281x = require('rpi-ws281x-native');
var NUM_LEDS = 2
var r = 255
var g = 0
var b = 0
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 () {
if (r==255) console.log('Red');
if (g==255) console.log('Green');
if (b==255) console.log('Blue');
for (var i = 0; i < NUM_LEDS; i++) {
pixelData[i] = rgb2Int(r,g,b);
}
ws281x.render(pixelData);
if (r==255) {
g=255; r=0;
} else if (g==255){
b=255; g=0;
} else {
r=255; b=0;
}
}, 2000 );
function rgb2Int(r, g, b) {
return ((r & 0xff) << 16) + ((g & 0xff) << 8) + (b & 0xff);
}
console.log('Press <ctrl>+C to exit.');