-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmotion.js
More file actions
68 lines (51 loc) · 1.27 KB
/
motion.js
File metadata and controls
68 lines (51 loc) · 1.27 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
57
58
59
60
61
62
63
64
65
66
67
68
var express = require('express');
var request = require('request');
var Tessel = require("tessel-io");
var five = require("johnny-five");
var board = new five.Board({
io: new Tessel()
});
board.on("ready", function() {
var led = new five.Led("b6");
var motion = new five.Motion("a6");
var hueURL = "http://192.168.0.3/api/7vO9zk1JtTHcbS58c7ZhHECpsxH62coI7gnZwT4J"
function waiting(){
async () => {
await sleep(100000)
//do stuff
}
}
motion.on("motionstart", () => led.on());
motion.on("motionstart", () => lightFiveOn());
motion.on("motionstart", () => waiting());
motion.on("motionend", () => led.off());
motion.on("motionend", () => lightFiveOff());
//changes light 5 state to on
function lightFiveOn(){
request({
uri: hueURL + "/lights/5/state/",
method: 'PUT',
json: {"on": true}
},
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
}
);
}
//changes light 5 state to off
function lightFiveOff(){
request({
uri: hueURL + "/lights/5/state/",
method: 'PUT',
json: {"on": false}
},
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
}
);
}
});