Skip to content

Instantly share code, notes, and snippets.

@ajfisher
Created August 18, 2016 08:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajfisher/3fda6f33669a859d44ade9048bc71687 to your computer and use it in GitHub Desktop.
Save ajfisher/3fda6f33669a859d44ade9048bc71687 to your computer and use it in GitHub Desktop.
Laser pan tilt code
{
"name": "lasertest",
"version": "1.0.0",
"description": "Used to pan tilt and fire a laser",
"main": "led.js",
"dependencies": {
"johnny-five": "^0.9.53"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "ajfisher <ajfisher.td@gmail.com>",
"license": "MIT"
}
var five = require("johnny-five");
var stdin = process.openStdin();
var pan, tilt, laser;
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.setRawMode(true);
var board = new five.Board({repl:false});
board.on("ready", () => {
pan = five.Servo({
type: "standard",
pin: 7,
});
tilt = five.Servo({
type: "standard",
pin: 8,
});
laser = five.Pin(4);
pan.center();
tilt.center();
console.log(pan.position);
/**laser.high();
tilt.sweep([105, 75]);
pan.sweep([105, 75]);**/
});
process.stdin.on("data", (key) => {
if (! key) return;
if (key == "c") {
laser.low()
console.log("Exit");
process.exit();
} else if (key == "a") {
if (pan.position < 180) {
console.log(pan.position);
pan.to(pan.position + 5);
}
} else if (key == "d") {
if (pan.position > 0) {
console.log(pan.position);
pan.to(pan.position - 5);
}
} else if (key == "w") {
if (tilt.position > 0) {
console.log(tilt.position);
tilt.to(tilt.position - 5);
}
} else if (key == "s") {
if (tilt.position < 180) {
console.log(tilt.position);
tilt.to(tilt.position + 5);
}
} else if (key == "l") {
if (laser.value) {
laser.low();
} else {
laser.high();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment