Skip to content

Instantly share code, notes, and snippets.

@tmpvar
Last active December 31, 2015 22:09
Show Gist options
  • Save tmpvar/8051933 to your computer and use it in GitHub Desktop.
Save tmpvar/8051933 to your computer and use it in GitHub Desktop.
leap motion to servofinger experiment
var five = require("johnny-five");
var ws = new (require('ws'))('ws://localhost:6437');
ws.on('open', console.log.bind(console, 'connected'));
ws.on('error', console.log.bind(console, 'ERROR:'));
(new five.Board()).on("ready", function() {
var servo = new five.Servo(11);
ws.on('message', function(data) {
var obj = JSON.parse(data.toString());
if (obj.pointables && obj.pointables.length) {
var fingerPos = obj.pointables[0].touchDistance;
servo.to((fingerPos+.5)*270);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment