-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdualservo.js
43 lines (37 loc) · 975 Bytes
/
dualservo.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 five = require("johnny-five"),
board = new five.Board();
var program = require('commander');
var keypress = require('keypress');
program
.version('1.0.0')
.option('-f, --fileName <program>', 'Program to load', String)
.parse(process.argv);
board.on("ready", function() {
console.log("board ready. left right arrow keys, 'q' to quit.");
var servoRightLeft = new five.Servo({
"pin": 9
});
var servoUpDown = new five.Servo({
"pin": 11
});
process.stdin.on('keypress', function (ch, key) {
// console.log('got "keypress"', key);
if (key && key.name == 'd') {
servoRightLeft.to(0);
}
if (key && key.name == 'a') {
servoRightLeft.to(180);
}
if (key && key.name == 's') {
servoUpDown.to(0);
}
if (key && key.name == 'w') {
servoUpDown.to(180);
}
if(key && key.name == 'q') {
process.exit(0);
}
});
process.stdin.setRawMode(true);
process.stdin.resume();
});