-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample03.js
44 lines (39 loc) · 1.12 KB
/
example03.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
var http = require("http").createServer(handler);
var io = require("socket.io").listen(http);
var fs = require("fs");
var firmata = require("firmata");
var board = new firmata.Board("/dev/ttyACM0", function(){
console.log("Connecting to Arduino");
console.log("Acctivation of Pin 13");
console.log("Acctivation of Pin 12");
board.pinMode(13, board.MODES.OUTPUT);
board.pinMode(12, board.MODES.OUTPUT);
});
function handler(req, res) {
fs.readFile(__dirname + "/example03.html",
function(err, data) {
if (err) {
res.writeHea(500, {"Content-Type": "text/plain"});
return res.end("Error loading html page.");
}
res.writeHead(200);
res.end(data);
});
}
http.listen(8080);
io.sockets.on("connection", function(socket) {
socket.on("commandToArduino", function(commandNo) {
if (commandNo == "1") {
board.digitalWrite(13, board.HIGH);
}
if (commandNo == "0") {
board.digitalWrite(13, board.LOW);
}
if (commandNo == "3") {
board.digitalWrite(12, board.HIGH);
}
if (commandNo == "2") {
board.digitalWrite(12, board.LOW);
}
});
});