Skip to content

Instantly share code, notes, and snippets.

@edgarsilva
Last active August 29, 2015 14:01
Show Gist options
  • Save edgarsilva/c7b668e8e1ce0198ec3d to your computer and use it in GitHub Desktop.
Save edgarsilva/c7b668e8e1ce0198ec3d to your computer and use it in GitHub Desktop.
leapmotion.js
var Cylon = require('cylon');
var Bot = function() {};
Bot.prototype.connections = [
{ name: 'leap', adaptor: 'leapmotion', port: '127.0.0.1:6437' },
{ name: 'digispark', adaptor: 'digispark' }
];
Bot.prototype.device = [
{ name: 'leap', driver: 'leapmotion', connection: 'leap'},
{ name: 'red', driver: 'led', pin: 0, connection: 'digispark' }
];
Bot.prototype.work = function(my) {
var y = 0;
var x = 0;
my.leap.on('hand', function(hand) {
y = hand.palmY.fromScale(50, 200).toScale(0, 90) | 0;
x = hand.palmX.fromScale(-30, 50).toScale(0, 90) | 0;
//console.log('hand ==>', hand);
});
every((0.5).second(), function() {
console.log('X val ==>', x);
console.log('Y val ==>', y);
if (x > 45) {
my.red.turnOn();
}else{
my.red.turnOff();
}
});
};
var bot = new Bot();
Cylon.robot(bot);
Cylon.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment