-
Notifications
You must be signed in to change notification settings - Fork 1
/
seervo.js
38 lines (29 loc) · 863 Bytes
/
seervo.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
const {Board, Servo} = require("johnny-five");
const keypress = require("keypress");
keypress(process.stdin);
const board = new Board();
board.on("ready", () => {
console.log("Use Up and Down arrows for CW and CCW respectively. Space to stop.");
const servo = new Servo.Continuous(10);
process.stdin.resume();
process.stdin.setEncoding("utf8");
process.stdin.setRawMode(true);
process.stdin.on("keypress", (ch, key) => {
if (!key) {
return;
}
if (key.name === "q") {
console.log("Quitting");
process.exit();
} else if (key.name === "up") {
console.log("CW");
servo.cw();
} else if (key.name === "down") {
console.log("CCW");
servo.ccw();
} else if (key.name === "space") {
console.log("Stopping");
servo.stop();
}
});
});