-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (34 loc) · 1.03 KB
/
index.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
var express = require('express');
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var five = require("johnny-five"),
board, potentiometer;
board = new five.Board();
board.on("ready", function() {
io.on('connection', function(socket){
console.log('io connection established');
});
http.listen(3000, function(){
console.log('listening on localhost:3000');
});
// Create a new `potentiometer` hardware instance.
potentiometer = new five.Sensor({
pin: "A2",
freq: 500
});
// Inject the `sensor` hardware into
// the Repl instance's context;
// allows direct command line access
board.repl.inject({
pot: potentiometer
});
// "data" get the current reading from the potentiometer
potentiometer.on("data", function() {
io.emit('pot-value', this.value);
});
});
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
app.use(express.static(__dirname + '/public'));