Any USB joystick or gamepad can be used for controls.
I'm using a very accurate gamepad from LogiTech. It also has a tiny receiver, which is good when the space is limited:
-
Logitech F710
together with the npm
joystick module:
Reading the gamepad is done like this:
Code:
var joystick = new (require('joystick'))(0, 3500, 350);
joystick.on('axis', function(event) {
// Typical Event: { time: 22283520, value: 32636, number: 3, type: 'axis', id: 0 }
var value = event.value / 32768; // Normalize to the range -1.0 - 0 - 1.0
if (event.number === 3) { // 3 is left/right on the right pad
steeringPos = value;
}
});