/
button.js
57 lines (46 loc) · 1.22 KB
/
button.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
//to run outside of terminal run t2 push button.js
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("b0");
var button = new five.Button("a0");
//button.on("press", () => led.on());
//button.on("release", () => led.off());
var hueURL = "http://192.168.0.3/api/7vO9zk1JtTHcbS58c7ZhHECpsxH62coI7gnZwT4J"
// initiate light on
button.on("press", () => lightFiveOn());
button.on("press", () => lightFiveBright());
button.on("release", () => led.off());
//changes light 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);
}
}
);
}
function lightFiveBright(){
request({
uri: hueURL + "/lights/5/state/",
method: 'PUT',
json: {"bri": 251}
},
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
}
);
}
});