Skip to content

Instantly share code, notes, and snippets.

@rwaldron
Created May 1, 2014 16:33
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 rwaldron/598df5dc32c1a9d43bdf to your computer and use it in GitHub Desktop.
Save rwaldron/598df5dc32c1a9d43bdf to your computer and use it in GitHub Desktop.
var Leap = require("leapjs");
var five = require("../lib/johnny-five.js");
var board = new five.Board();
var scale = five.Fn.scale;
var max = 0;
var min = 0;
function toDegrees(value) {
var degrees = value > 0 ?
scale(value, max, min, 0, 90) :
scale(value, max, min, 90, 180);
return degrees | 0;
}
board.on("ready", function() {
var steering = new five.Servo(6);
var distance = new IR.Distance({
device: "GP2Y0A02YK0F",
pin: "A0"
});
Leap.loop(function(frame) {
frame.hands.forEach(function(hand, index) {
var roll = hand.roll();
max = Math.max(max, roll);
min = Math.min(min, roll);
steering.to(toDegrees(roll));
});
});
distance.on("change", function() {
// collision detection here!!
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment