Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
61 lines (56 loc) · 2.09 KB
/
Copy pathapp.js
File metadata and controls
61 lines (56 loc) · 2.09 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
var fs = require('fs')
, http = require('http')
, five = require('johnny-five'), board
, socketio = require('socket.io');
//https://github.com/scottkellie/Node_Arduino_HTML5_Websockets
var server = http.createServer(function (req, res) {
res.writeHead(200, { 'Content-type': 'text/html' });
res.end(fs.readFileSync(__dirname + '/index.html'));
}).listen(8888, function () {
//create johnny-five arduino connection
board = new five.Board();
//initialize and declare variables related to Arduino
board.on("ready", function () {
console.log('Board connected'),
lcd1 = new five.LCD({ pins: [12, 11, 5, 4, 3, 2] }),
// in8 = new five.Sensor({pin:"A8",freq:25}),
led13 = new five.Led(13),
console.log('led created'),
lcd1.on("ready", function () {
// creates a heart!
lcd1.clear(),
lcd1.createChar(0x07,
[0x00, 0x0a, 0x1f, 0x1f, 0x0e, 0x04, 0x00, 0x00]);
lcd1.print('initialised');
});
console.log('Listening at: http://localhost:8888');
socketio.listen(server).on('connection', function (socket) {
socket.on('command', function (msg) {
console.log(msg);
});
socket.on('message', function (msg) {
var inmsg = msg.toString();
//var queryData = msg.parse(msg);
date = new Date(),
dateNow = Date.now(),
timeValH = date.getHours(),
timeValM = date.getMinutes(),
timeValS = date.getSeconds(),
dateTime = (timeValH + '.' + timeValM + '.' + timeValS),
lcd1.cursor();
lcd1.blink();
lcd1.setCursor(2,6);
setTimeout(function () {
lcd1.clear().print(dateTime);
console.log(dateTime);
}, 600);
led13.strobe(inmsg),
lcd1.setCursor(1,1),
lcd1.print(inmsg);
lcd1.print('Led strobing at ' + inmsg + 'ms');
console.log('Message Received: ', inmsg);
socket.broadcast.emit('message', inmsg);
});
});
});
});