Skip to content

Instantly share code, notes, and snippets.

@cylinderStudio
Last active August 29, 2015 14:07
Show Gist options
  • Save cylinderStudio/03d12ec18ef9a62ae481 to your computer and use it in GitHub Desktop.
Save cylinderStudio/03d12ec18ef9a62ae481 to your computer and use it in GitHub Desktop.
var Cylon = require('cylon');
var hand;
var roll = 0; // side:side goes up:down
var pitch = 0; // front:back goes up:down
var now;
Cylon.robot({
connections: [{ name: 'leapmotion', adaptor: 'leapmotion', port: '127.0.0.1:6437'},
{name: 'arduino', adaptor: 'firmata', port: '/dev/tty.usbmodem1411'}],
devices: [{ name: 'leapmotion', driver: 'leapmotion', connection: 'leapmotion'},
// {name: 'led', driver: 'led', pin: 13, connection: 'arduino'},
{name: 'servo1', driver: 'servo', pin: 9, connection: 'arduino'},
{name: 'servo2', driver: 'servo', pin: 10, connection: 'arduino'}],
work: function(my) {
var time = Date.now();
my.leapmotion.on('frame', function(frame) {
// Limit to 100hz
now = Date.now();
if (now >= time + 10) {
time = now;
if (frame.hands.length > 0) {
hand = frame.hands[0];
roll = hand.roll() * (180/Math.PI);
roll = Math.floor(roll + 90);
pitch = hand.pitch() * (180/Math.PI);
pitch = Math.floor(pitch + 90);
//my.led.turnOn();
if (roll > -1 && roll < 181) { my.servo1.angle(roll); }
if (pitch > -1 && pitch < 181) { my.servo2.angle(pitch); }
} else {
// my.led.turnOff();
my.servo1.angle(90);
my.servo2.angle(90);
}
}
});
}
}).start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment