-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp5v.js
64 lines (50 loc) · 1.57 KB
/
app5v.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
57
58
59
60
61
62
var express = require('express'),
app = express(),
server = require('http').Server(app),
io = require('socket.io')(server),
five = require("johnny-five"),
led5V;
app.disable('x-powered-by');
app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', "http://"+req.headers.host+':8000');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
next();
}
);
app.use("/", express.static(__dirname + "/public"));
app.get('/', function (req, res) {
res.sendfile(__dirname + '/public/index.html');
});
function invertColor(hexTripletColor) {
var color = hexTripletColor;
color = color.substring(1); // remove #
color = parseInt(color, 16); // convert to integer
color = 0xFFFFFF ^ color; // invert three bytes
color = color.toString(16); // convert to hex
color = ("000000" + color).slice(-6); // pad with leading zeros
color = "#" + color; // prepend #
return color;
}
server.listen(3000, "127.0.0.1");
five.Board().on("ready", function() {
var led = new five.Led.RGB({
pins: {
red: 3,
green: 5,
blue: 6
}
});
this.repl.inject({
led: led
});
led.on();
led.color("#00FFFF");
io.on('connection', function (socket) {
socket.on("changeColor",function(data){
led5V = invertColor(data.hex)
led.color(led5V);
socket.emit('retorno', data);
});
});
});