UNPKG

johnny-five

Version:

The JavaScript Robotics and Hardware Programming Framework. Use with: Arduino (all models), Electric Imp, Beagle Bone, Intel Galileo & Edison, Linino One, Pinoccio, Raspberry Pi, Spark Core, TI Launchpad and more!

39 lines (29 loc) 846 B
var five = require("../lib/johnny-five.js"); var keypress = require("keypress"); keypress(process.stdin); var board = new five.Board(); board.on("ready", function() { console.log("Use Up and Down arrows for CW and CCW respectively. Space to stop."); var servo = new five.Servo.Continuous(10).stop(); process.stdin.resume(); process.stdin.setEncoding("utf8"); process.stdin.setRawMode(true); process.stdin.on("keypress", function(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(); } }); });