-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
52 lines (40 loc) · 1.25 KB
/
index.js
File metadata and controls
52 lines (40 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
var five = require("johnny-five");
var board = new five.Board();
var port = 3030;
var express = require('express'),
app = express(),
http = require('http').Server(app),
io = require('socket.io')(http);
app.use('/rangeslider', express.static(__dirname + '/node_modules/rangeslider.js/dist/'));
app.get('/', function(req, res,next) {
res.sendFile(__dirname + '/index.html');
});
io.on('connection', function(socket){
console.log("A user connected");
socket.on('disconnect', function(){
console.log('A user disconnected');
});
socket.on('changeLight', function(obj){
console.log("received changeLight object", obj);
board.emit("changeLight", obj);
});
});
http.listen(port, function() {
console.log("listening on port " + port);
});
board.on("ready", function() {
console.log('Board is ready');
var myLED = new five.Led(11);
board.repl.inject({
ledRed: myLED
});
board.on('changeLight', function(obj){
if(obj.lightValue==null)obj.lightValue=0;
console.log("Turning brightness to ", obj.lightValue);
myLED.brightness(obj.lightValue);
});
this.on('exit', function(){
io.emit('server_exit');
myLED.brightness(0);
});
});