forked from luxdvie/WS2812Controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrip.js
More file actions
56 lines (47 loc) · 1.12 KB
/
strip.js
File metadata and controls
56 lines (47 loc) · 1.12 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
/*
* Put your number of LEDs here.
*/
var NUM_LEDS = 150;
var ws281x = require('rpi-ws281x-native');
var pixelData = new Uint32Array(NUM_LEDS);
ws281x.init(NUM_LEDS);
var Lights = [];
function strip() {
this.NUM_LEDS = NUM_LEDS;
this.Mode = "";
this.Lights = [];
this.Clear = function () {
ws281x.reset();
};
/*
* Clear all LEDs back to 0x00000 and render
*/
this.Stop = function () {
strip.Clear();
CurrentMode = MODES.CLEAR;
};
/*
* Assign the brightness of the whole strip.
*/
this.SetBrightness = function (brightness) {
ws281x.setBrightness(brightness);
};
/*
* Set a single color for all LEDs
*/
this.SetStripColor = function (color) {
for (var i = 0; i < NUM_LEDS; i++) {
this.Lights[i] = color;
}
this.Render();
};
this.Render = function () {
var tmp = [];
for (var i = 0; i < NUM_LEDS; i++) {
if (i > NUM_LEDS) break;
tmp[i] = this.Lights[i];
}
ws281x.render(tmp);
};
}
module.exports = new strip();