Created
August 18, 2016 08:47
-
-
Save ajfisher/3fda6f33669a859d44ade9048bc71687 to your computer and use it in GitHub Desktop.
Laser pan tilt code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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 <[email protected]>", | |
"license": "MIT" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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