-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
69 lines (54 loc) · 1.69 KB
/
index.js
File metadata and controls
69 lines (54 loc) · 1.69 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
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Server
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
var express = require('express');
var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);
app.use(express.static('assets'))
server.listen(8081);
// WARNING: app.listen(80) will NOT work here!
app.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html');
console.log('Server running on port 8080')
});
io.on('connection', function (socket) {
console.log('Server Connected')
});
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Motion
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
// Configure johnny-five
var five = require('johnny-five');
var board = new five.Board();
board.on("ready",function() {
var led = new five.Led(13);
var motion = new five.Motion(4);
// "calibrated" occurs once, at the beginning of a session,
motion.on("calibrated", function() {
console.log("Motion Calibrated");
led.blink();
// Emit to Client
io.emit('motionCalibrated');
});
// "motionstart" events are fired when the "calibrated"
// proximal area is disrupted, generally by some form of movement
motion.on("motionstart", function() {
console.log("Motion Start");
led.stop();
led.on();
// Emit to Client
io.emit('motionStart');
});
// "motionend" events are fired following a "motionstart" event
// when no movement has occurred in X ms
motion.on("motionend", function() {
console.log("Motion End");
led.stop();
led.off();
});
});