-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharduino.js
85 lines (79 loc) · 2.28 KB
/
arduino.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
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
var io = require('socket.io-client');
var socket = io.connect('http://localhost:3000', {reconnect: true});
var five = require('johnny-five');
var board = new five.Board({
repl:false
});
board.on('ready', function () {
var servos = {
ab: new five.Servo({
pin: 3,
center: true
}),
downright: new five.Servo({
pin: 9,
center: true
}),
upleft: new five.Servo({
pin: 10,
center: true
}),
startselect: new five.Servo({
pin: 11,
center: true
})
};
socket.on("arduino", function(msg) {
console.log("got it: " + msg);
switch(msg) {
case 'A':
servos['ab'].to(150);
setTimeout(function() {
servos['ab'].center();
}, 500);
break;
case 'B':
servos['ab'].to(40);
setTimeout(function() {
servos['ab'].center();
}, 500);
break;
case 'L':
servos['upleft'].to(40);
setTimeout(function() {
servos['upleft'].center();
}, 500);
break;
case 'R':
servos['downright'].to(150);
setTimeout(function() {
servos['downright'].center();
}, 500);
break;
case 'Down':
servos['downright'].to(40);
setTimeout(function() {
servos['downright'].center();
}, 500);
break;
case 'Up':
servos['upleft'].to(150);
setTimeout(function() {
servos['upleft'].center();
}, 500);
break;
case 'Start':
servos['startselect'].to(150);
setTimeout(function() {
servos['startselect'].center();
}, 500);
break;
case 'Select':
servos['startselect'].to(40);
setTimeout(function() {
servos['startselect'].center();
}, 500);
break;
}
});
});