-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroom.js
More file actions
170 lines (149 loc) · 3.57 KB
/
room.js
File metadata and controls
170 lines (149 loc) · 3.57 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
//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() {
//LED and button to turn 3 living room lights to sun
var ledSun = new five.Led("a5");
var buttonSun = new five.Button("a2");
var hueURL = "http://192.168.0.3/api/7vO9zk1JtTHcbS58c7ZhHECpsxH62coI7gnZwT4J"
// Turn LED on board on and off
buttonSun.on("press", () => ledSun.on());
buttonSun.on("release", () => ledSun.off());
// Lights 5 6 8 to on
buttonSun.on("press", () => lightFiveOn());
buttonSun.on("press", () => lightSixOn());
buttonSun.on("press", () => lightEightOn());
// Lights 5 6 8 to bright
buttonSun.on("press", () => lightFiveBright());
buttonSun.on("press", () => lightSixBright());
buttonSun.on("press", () => lightEightBright());
// Light 5 6 8 to Sun Hue
buttonSun.on("press", () => lightFiveSun());
buttonSun.on("press", () => lightSixSun());
buttonSun.on("press", () => lightEightSun());
//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);
}
}
);
}
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);
}
}
);
}
function lightFiveSun(){
request({
uri: hueURL + "/lights/5/state/",
method: 'PUT',
json: {"hue": 10778}
},
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
}
);
}
//changes light 6 state to on
function lightSixOn(){
request({
uri: hueURL + "/lights/6/state/",
method: 'PUT',
json: {"on": true}
},
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
}
);
}
function lightSixBright(){
request({
uri: hueURL + "/lights/6/state/",
method: 'PUT',
json: {"bri": 251}
},
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
}
);
}
function lightSixSun(){
request({
uri: hueURL + "/lights/6/state/",
method: 'PUT',
json: {"hue": 10778}
},
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
}
);
}
//changes light 8 state to on
function lightEightOn(){
request({
uri: hueURL + "/lights/8/state/",
method: 'PUT',
json: {"on": true}
},
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
}
);
}
function lightEightBright(){
request({
uri: hueURL + "/lights/8/state/",
method: 'PUT',
json: {"bri": 251}
},
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
}
);
}
function lightEightSun(){
request({
uri: hueURL + "/lights/8/state/",
method: 'PUT',
json: {"hue": 10778}
},
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
}
);
}
});