-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathstrip.js
58 lines (50 loc) · 1.01 KB
/
strip.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* Put your number of LED's here
*/
var NUM_LEDS = 10;
var ws281x = require("rpi-ws281x-native");
var pixelData = new Uint32Array(NUM_LEDS);
var Lights = [];
ws281x.init(NUM_LEDS);
function strip() {
this.NUM_LEDS = NUM_LEDS;
this.Mode = "";
this.Lights = [];
this.Clear = function () {
ws281x.reset();
};
/**
* Clear all LED's 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 LED's
*/
this.SetStripColor = function (color) {
for (var i = 0; i < NUM_LEDS; i++) {
this.Lights[i] = color;
}
this.Render();
};
/**
* Render the current state of the LED strip
*/
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();