Skip to content

Instantly share code, notes, and snippets.

@kopiro
Created December 10, 2014 08:43
Show Gist options
  • Select an option

  • Save kopiro/0999f063bed4159f671b to your computer and use it in GitHub Desktop.

Select an option

Save kopiro/0999f063bed4159f671b to your computer and use it in GitHub Desktop.
Control XBOX controller vibration with LEAP motion
var Leap = require('leapjs');
var XboxController = require('xbox-controller');
var xbox = new XboxController;
Leap.loop(function (frame) {
if (frame.hands.length === 0) {
xbox.rumble(0, 0);
return;
}
frame.hands.forEach(function(hand) {
var left = Math.max(0, - hand.palmPosition[0] / 250);
var right = Math.max(0, hand.palmPosition[0] / 250);
var power = (400 - hand.palmPosition[1]) / 400;
var rumbles = [
Math.max(0, Math.min(255, 100 * power + 150 * left)),
Math.max(0, Math.min(255, 100 * power + 150 * right))
];
xbox.rumble(rumbles[0], rumbles[1]);
xbox.setLed( left>right ? 0x06 : 0x07 );
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment