-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
54 lines (42 loc) · 1.25 KB
/
test.js
File metadata and controls
54 lines (42 loc) · 1.25 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
var Yeelight = require('node-yeelight');
var y = new Yeelight;
y.on('ready', function() {
y.discover(); // scan network for active Yeelights
});
y.on('deviceadded', function(device) {
y.connect(device); // attempt to connect
});
y.on('deviceconnected', function(device) {
console.log('yeelight connected.');
//console.log(device);
// turn Yeelight on/off
// y.setPower(
// device, // device object
// true, // device state (true/false)
// 300 // transition speed in ms
// );
// set Yeelight brightness
// y.setBrightness(
// device, // device object
// 50, // brightness percentage (1-100)
// 300 // transition speed in ms
// );
console.log('device connected');
var state = true;
setInterval(function() {
y.setPower(device, state, 100);
state = state ? false : true;
}, 300);
// function toggle(){
// y.setPower(device, state, 2000);
// state = state ? false : true;
// var gape = Math.random()*20000;
// console.log(gape);
// setTimeout(function(){
// toggle();
// }, gape);
//
// }
// toggle();
});
y.listen();