Created
December 10, 2014 08:43
-
-
Save kopiro/0999f063bed4159f671b to your computer and use it in GitHub Desktop.
Control XBOX controller vibration with LEAP motion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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