htmlarduinojoystickgamepad-api

Arduino joystick to web gamepad


I'm using a Arduino Leonardo with a b10k pot. I want to have this pot act as a gamepad (paddle) in a HTML-game. I'm using ArduinoJoystickLibrary and mapping the analog value(0-1023) to a range of -127 to 127.

Like this:

Joystick[0].setXAxis(map(analogRead(A0), 0, 1023, -127, 127));

Windows 7 is is happy with this and if I run 'Set up USB controllers' and test the device is responds perfect from edge to edge. So far so good, seems like I have made myself a perfectly working USB joystick with one axis.

When testing the device for a HTML5 Gamepad (here) (and here) I get INFINITY and -INFINITY for the x-axis.

My problem is now that the HTML5 Gamepad Api expects a range from -1 to 1.

Any ideas how I can get my Arduino Joystick to play well with the HTML5 gamepad spec?


Solution

  • I was able to get the single version of the library to work correctly in both Chrome 47 and Firefox 43. The two and three controller versions work correctly in Firefox 43, but in Chrome 47 I see the issue you are describing. This may be an issue with the Chrome browser since the Gamepad API is young.