-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdemo-color.js
53 lines (50 loc) · 1.9 KB
/
demo-color.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
'use strict';
var Playbulb = require('./playbulb');
function rand256() {
return randInt(256);
}
function randInt(n) {
return Math.floor(Math.random() * n);
}
var pb = new Playbulb.PlaybulbColor();
pb.ready(function () {
console.log("Playbulb Color Demo Mode");
var flashMax = 20;
var doEffects = function (effectNum) {
var r = rand256(), g = rand256(), b = rand256();
switch (effectNum) {
default:
case 0:
console.log("Running PULSE effect at max speed with red: " + r + ", green: " + g + ", blue: " + b);
pb.setPulse(0, r, g, b, 1.0);
break;
case 1:
console.log("Running FLASH effect at max speed with red: " + r + ", green: " + g + ", blue: " + b);
pb.setFlash(0, r, g, b, 1.0);
break;
case 2:
console.log("Running RAINBOW JUMP effect at max speed with red: " + r + ", green: " + g + ", blue: " + b);
pb.setRainbowJump(0, r, g, b, 1.0);
break;
case 3:
console.log("Running RAINBOW FADE effect at max speed with red: " + r + ", green: " + g + ", blue: " + b);
pb.setRainbowFade(0, r, g, b, 1.0);
break;
case 4:
setTimeout(function () { changeColours(flashMax); }, 2500);
return;
}
setTimeout(function() { doEffects(effectNum + 1); }, 5000);
};
var changeColours = function (flashCount) {
if (flashCount === 0) {
doEffects(0);
} else {
var r = rand256(), g = rand256(), b = rand256();
console.log("Setting colour to red: " + r + ", green: " + g + ", blue: " + b);
pb.setColor(0, r, g, b);
setTimeout(function() { changeColours(flashCount - 1); }, 100);
}
};
changeColours(flashMax);
});