GithubHelp home page GithubHelp logo

mheironimus / arduinojoysticklibrary Goto Github PK

View Code? Open in Web Editor NEW
2.0K 129.0 396.0 140 KB

An Arduino library that adds one or more joysticks to the list of HID devices an Arduino Leonardo or Arduino Micro can support.

License: GNU Lesser General Public License v3.0

C++ 100.00%
gamepad arduino-micro arduino-library joystick-library arduino-leonardo

arduinojoysticklibrary's Introduction

Arduino Joystick Library

Version 2.1.1

This library can be used with Arduino IDE 1.6.6 or above (see Wiki - Testing Details for more information) to add one or more joysticks (or gamepads) to the list of HID devices an Arduino Leonardo or Arduino Micro (or any Arduino clone that is based on the ATmega32u4) can support. This library will also work with the Arduino Due, thanks to @Palakis. A complete list of supported boards can be found in the Wiki - Supported Boards. This will not work with Arduino IDE 1.6.5 (or below) or with non-32u4 based Arduino devices (e.g. Arduino UNO, Arduino MEGA, etc.).

Features

The joystick or gamepad can have the following features:

  • Buttons (default: 32)
  • Up to 2 Hat Switches
  • X, Y, and/or Z Axis (up to 16-bit precision)
  • X, Y, and/or Z Axis Rotation (up to 16-bit precision)
  • Rudder (up to 16-bit precision)
  • Throttle (up to 16-bit precision)
  • Accelerator (up to 16-bit precision)
  • Brake (up to 16-bit precision)
  • Steering (up to 16-bit precision)

Installation Instructions

The following instructions can be used to install the latest version of the library in the Arduino IDE (thanks to @per1234 for this update):

  1. Download https://github.com/MHeironimus/ArduinoJoystickLibrary/archive/master.zip
  2. In the Arduino IDE, select Sketch > Include Library > Add .ZIP Library.... Browse to where the downloaded ZIP file is located and click Open. The Joystick library's examples will now appear under File > Examples > Joystick.

Examples

Simple example

#include <Joystick.h>

// Create the Joystick
Joystick_ Joystick;

// Constant that maps the physical pin to the joystick button.
const int pinToButtonMap = 9;

void setup() {
	// Initialize Button Pins
	pinMode(pinToButtonMap, INPUT_PULLUP);

	// Initialize Joystick Library
	Joystick.begin();
}

// Last state of the button
int lastButtonState = 0;

void loop() {

	// Read pin values
	int currentButtonState = !digitalRead(pinToButtonMap);
	if (currentButtonState != lastButtonState)
	{
	Joystick.setButton(0, currentButtonState);
	lastButtonState = currentButtonState;
	}

	delay(50);
}

Included Examples

The following example Arduino sketch files are included in this library:

Simple Samples

  • JoystickButton - Creates a Joystick and maps pin 9 to button 0 of the joystick, pin 10 to button 1, pin 11 to button 2, and pin 12 to button 3.
  • JoystickKeyboard - Creates a Joystick and a Keyboard. Maps pin 9 to Joystick Button 0, pin 10 to Joystick Button 1, pin 11 to Keyboard key 1, and pin 12 to Keyboard key 2.
  • GamepadExample - Creates a simple Gamepad with an Up, Down, Left, Right, and Fire button.
  • FunduinoJoystickShield - Creates a simple Gamepad using a Funduino Joystick Shield (https://protosupplies.com/product/funduino-joystick-shield-v1-a/).
  • ArcadeStickExample - Simple arcade stick example that demonstrates how to read twelve Arduino Pro Micro digital pins and map them to the library (thanks to @nebhead for this example). NOTE: This sketch is for the Arduino Pro Micro only.

Used for Testing

  • JoystickTest - Simple test of the Joystick library. It exercises many of the Joystick library’s functions when pin A0 is grounded.
  • MultipleJoystickTest - Creates 4 Joysticks using the library (each with a slightly different configuration) and exercises the first 16 buttons (if present), the X axis, and the Y axis of each joystick when pin A0 is grounded.
  • FlightControllerTest - Creates a Flight Controller and tests 32 buttons, the X and Y axis, the Throttle, and the Rudder when pin A0 is grounded.
  • HatSwitchTest - Creates a joystick with two hat switches. Grounding pins 4 - 11 cause the hat switches to change position.
  • DrivingControllerTest - Creates a Driving Controller and tests 4 buttons, the Steering, Brake, and Accelerator when pin A0 is grounded.

Joystick Library API

The following API is available if the Joystick library in included in a sketch file.

Joystick_(...)

Constructor used to initialize and setup the Joystick. The following optional parameters are available:

  • uint8_t hidReportId - Default: 0x03 - Indicates the joystick's HID report ID. This value must be unique if you are creating multiple instances of Joystick. Do not use 0x01 or 0x02 as they are used by the built-in Arduino Keyboard and Mouse libraries.
  • uint8_t joystickType - Default: JOYSTICK_TYPE_JOYSTICK or 0x04 - Indicates the HID input device type. Supported values:
    • JOYSTICK_TYPE_JOYSTICK or 0x04 - Joystick
    • JOYSTICK_TYPE_GAMEPAD or 0x05 - Gamepad
    • JOYSTICK_TYPE_MULTI_AXIS or 0x08 - Multi-axis Controller
  • uint8_t buttonCount - Default: 32 - Indicates how many buttons will be available on the joystick.
  • uint8_t hatSwitchCount - Default: 2 - Indicates how many hat switches will be available on the joystick. Range: 0 - 2
  • bool includeXAxis - Default: true - Indicates if the X Axis is available on the joystick.
  • bool includeYAxis - Default: true - Indicates if the Y Axis is available on the joystick.
  • bool includeZAxis - Default: true - Indicates if the Z Axis (in some situations this is the right X Axis) is available on the joystick.
  • bool includeRxAxis - Default: true - Indicates if the X Axis Rotation (in some situations this is the right Y Axis) is available on the joystick.
  • bool includeRyAxis - Default: true - Indicates if the Y Axis Rotation is available on the joystick.
  • bool includeRzAxis - Default: true - Indicates if the Z Axis Rotation is available on the joystick.
  • bool includeRudder - Default: true - Indicates if the Rudder is available on the joystick.
  • bool includeThrottle - Default: true - Indicates if the Throttle is available on the joystick.
  • bool includeAccelerator - Default: true - Indicates if the Accelerator is available on the joystick.
  • bool includeBrake - Default: true - Indicates if the Brake is available on the joystick.
  • bool includeSteering - Default: true - Indicates if the Steering is available on the joystick.

The following constants define the default values for the constructor parameters listed above:

  • JOYSTICK_DEFAULT_REPORT_ID is set to 0x03
  • JOYSTICK_DEFAULT_BUTTON_COUNT is set to 32
  • JOYSTICK_DEFAULT_HATSWITCH_COUNT is set to 2

Joystick.begin(bool initAutoSendState)

Starts emulating a game controller connected to a computer. By default, all methods update the game controller state immediately. If initAutoSendState is set to false, the Joystick.sendState method must be called to update the game controller state.

Joystick.end()

Stops the game controller emulation to a connected computer (Note: just like the Arduino Keyboard.h and Mouse.h libraries, the end() function does not actually do anything).

Joystick.setXAxisRange(int32_t minimum, int32_t maximum)

Sets the range of values that will be used for the X axis. Default: 0 to 1023

Joystick.setXAxis(int32_t value)

Sets the X axis value. See setXAxisRange for the range.

Joystick.setYAxisRange(int32_t minimum, int32_t maximum)

Sets the range of values that will be used for the Y axis. Default: 0 to 1023

Joystick.setYAxis(int32_t value)

Sets the Y axis value. See setYAxisRange for the range.

Joystick.setZAxisRange(int32_t minimum, int32_t maximum)

Sets the range of values that will be used for the Z axis. Default: 0 to 1023

Joystick.setZAxis(int32_t value)

Sets the Z axis value. See setZAxisRange for the range.

Joystick.setRxAxisRange(int32_t minimum, int32_t maximum)

Sets the range of values that will be used for the X axis rotation. Default: 0 to 1023

Joystick.setRxAxis(int32_t value)

Sets the X axis rotation value. See setRxAxisRange for the range.

Joystick.setRyAxisRange(int32_t minimum, int32_t maximum)

Sets the range of values that will be used for the Y axis rotation. Default: 0 to 1023

Joystick.setRyAxis(int32_t value)

Sets the Y axis rotation value. See setRyAxisRange for the range.

Joystick.setRzAxisRange(int32_t minimum, int32_t maximum)

Sets the range of values that will be used for the Z axis rotation. Default: 0 to 1023

Joystick.setRzAxis(int32_t value)

Sets the Z axis rotation value. See setRzAxisRange for the range.

Joystick.setRudderRange(int32_t minimum, int32_t maximum)

Sets the range of values that will be used for the Rudder. Default: 0 to 1023

Joystick.setRudder(int32_t value)

Sets the Rudder value. See setRudderRange for the range.

Joystick.setThrottleRange(int32_t minimum, int32_t maximum)

Sets the range of values that will be used for the Throttle. Default: 0 to 1023

Joystick.setThrottle(int32_t value)

Sets the Throttle value. See setThrottleRange for the range.

Joystick.setAcceleratorRange(int32_t minimum, int32_t maximum)

Sets the range of values that will be used for the Accelerator. Default: 0 to 1023

Joystick.setAccelerator(int32_t value)

Sets the Accelerator value. See setAcceleratorRange for the range.

Joystick.setBrakeRange(int32_t minimum, int32_t maximum)

Sets the range of values that will be used for the Brake. Default: 0 to 1023

Joystick.setBrake(int32_t value)

Sets the Brake value. See setBrakeRange for the range.

Joystick.setSteeringRange(int32_t minimum, int32_t maximum)

Sets the range of values that will be used for the Steering. Default: 0 to 1023

Joystick.setSteering(int32_t value)

Sets the Steering value. See setSteeringRange for the range.

Joystick.setButton(uint8_t button, uint8_t value)

Sets the state (0 or 1) of the specified button (range: 0 - (buttonCount - 1)). The button is the 0-based button number (i.e. button #1 is 0, button #2 is 1, etc.). The value is 1 if the button is pressed and 0 if the button is released.

Joystick.pressButton(uint8_t button)

Press the indicated button (range: 0 - (buttonCount - 1)). The button is the 0-based button number (i.e. button #1 is 0, button #2 is 1, etc.).

Joystick.releaseButton(uint8_t button)

Release the indicated button (range: 0 - (buttonCount - 1)). The button is the 0-based button number (i.e. button #1 is 0, button #2 is 1, etc.).

Joystick.setHatSwitch(int8_t hatSwitch, int16_t value)

Sets the value of the specified hat switch. The hatSwitch is 0-based (i.e. hat switch #1 is 0 and hat switch #2 is 1). The value is from 0° to 360°, but in 45° increments. Any value less than 45° will be rounded down (i.e. 44° is rounded down to 0°, 89° is rounded down to 45°, etc.). Set the value to JOYSTICK_HATSWITCH_RELEASE or -1 to release the hat switch.

Joystick.sendState()

Sends the updated joystick state to the host computer. Only needs to be called if AutoSendState is false (see Joystick.begin for more details).

See the Wiki for more details on things like FAQ, supported boards, testing, etc.

arduinojoysticklibrary's People

Contributors

e-bonner avatar mheironimus avatar nebhead avatar palakis avatar per1234 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arduinojoysticklibrary's Issues

Arduino Micro Issues

Have tried to use the example sketches with arduino micro and they compile and upload, but the arduino is not recognised as a joystick by the computer for some reason. Used the older library before and that worked out well, this one would suit my needs better though.

I'm using Arduino 1.6.12 and Windows 7.

Any ARM board supported?

Hi,
looking to use this fantastic library for a more CPU demanding project project I'm asking if any ArduinoMKRZero or Teensy board is supported or tested.
Sorry for rise this as an issue.
Thanks.

32 Buttons + 2 hat switch

(Sorry I don´t speak english this is traslated with Google Tool)

Hi. I am interested in creating my buttons box, I do not know anything about arduino programming so I read a lot of project examples but don´t find information or examples of how to use the 32 buttons. My idea is to use the 32 buttons and the 2 hat switch which gives a total of 40 buttons. As the arduino leonardo does not have 40 digital ports I imagine that you have to define an array of 8 rows and 5 columns and assign them to the 13 digital ports. But how do I do this? Can you help me? (I do not need any analog ports, just buttons) Thank you very much.

Newbie question: Using a potentiometer as analog axis?

Just found this great library :) Thank you already in advance MHeironimus! I want to build a hand brake for my car sim. So I thought (for the electronics) I only need a suitable version of Arduino, a potentiometer and this library. Is this correct? I tried to find the part of the code that specifies the analog input pin for the potentiometer, but could nhot find it. Am I missing something very elementary here? (probably yes ;)

Thanks again!

compatibility with clones

First, big thanks to MHeironimus for this awesome library.

I am just giving a feedback, that this library is working fine with a robotdyn micro 32u4. Good thing is, this boards are really cheap (5.85$ with shipping). I am using it for my custom controller with a raspberry pi zero.

best regards,

Controller reporting as driving wheel

Would it be possible for the controller to be reported as a driving wheel (or possibly other types controllers). Some racing games detect driving wheels specifically, which greatly ehances configuration.

Sample code

I have an arduino leonardo with a joystick (4 buttons) and 6 buttons. Is there any sample code out there which will make this look like a joystick? I've tried the test joystick code but it doesn't seem to output anything. Do I need the joystick (up, down, left, right) outputs plugged to specific pins on the arduino and likewise for the six buttons?

Thanks in advance,
David

Arduino Pro Micro

I'm having some problems here...

ccK89KZw.ltrans0.ltrans.o: In function `__base_ctor ':
Joystick.cpp:439: undefined reference to `DynamicHID()'
undefined reference to `DynamicHID_::AppendDescriptor(DynamicHIDSubDescriptor*)'
collect2.exe: error: ld returned 1 exit status
exit status 1

Editing "joystick.h" and changing

#include <DynamicHID/DynamicHID.h>

with

#include "DynamicHID/DynamicHID.h"

Solves that issue but brings new issues:

cKCayaX.ltrans0.ltrans.o: In function `__base_ctor ':
libraries\joystick/Joystick.cpp:439: undefined reference to `DynamicHID()'
libraries\joystick/Joystick.cpp:439: undefined reference to `DynamicHID_::AppendDescriptor(DynamicHIDSubDescriptor*)'
collect2.exe: error: ld returned 1 exit status
exit status 1

ButtonState Preference

I have a 3 button game pad here is my code:

#include <Joystick.h>

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_GAMEPAD,
  3, 0,                  // Button Count, Hat Switch Count
  false, false, false,   // X and Y, but no Z Axis
  false, false, false,   // No Rx, Ry, or Rz
  false, false,          // No rudder or throttle
  false, false, false);  // No accelerator, brake, or steering

void setup() {
  // Initialize Button Pins
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);

  // Initialize Joystick Library
  Joystick.begin();
}

// Constant that maps the phyical pin to the joystick button.
const int pinToButtonMap = 2;

// Last state of the button
int lastButtonState[3] = {0,0,0};

void loop() {

  // Read pin values
  for (int index = 0; index < 3; index++)
  {
    int currentButtonState = !digitalRead(index + pinToButtonMap);
    if (currentButtonState != lastButtonState[index])
    {
      if (index < 4) {
        Joystick.setButton(index, currentButtonState);
        lastButtonState[index] = currentButtonState;
      } else {
        if (currentButtonState) {
          Joystick.setButton(index, currentButtonState);
          lastButtonState[index] = currentButtonState;
        }
      }
    }
  }

  delay(10);
}

My button on pin 2 is normally on, how do I reverse this in the code so that the state is normally off.

Thanks in advance,
-b3ck

3Joy X 8Axis

Hello, Great thx for the Job.
I need 3 joy , which must have 8axis. So 24 Axis summary.
Can I make it by joystick3.h? What can i change there for my task?

Arduino Mega

Well, this is acually not a real Issue, so maybe mr. Heironimus would prefer to move this on the documentation, or whatever.

I would like to report my findings to everyone interested on using the ArduinoJoystickLibrary on the Arduino Mega. Why the Mega? Well, with so many pins, you can build a double controller binding leds to certain buttons, and that is what I wanted to build an arcade cabinet using as less hardware as possible.

It is definitely possible to use it!

  1. You have to flash the NicoHood HoodLoader2 on the 16u2 of the Mega. It is a very simple process if you follow the instructions.
  2. Due to the fact that the 16u2 has very limited resources, you must stick to version 1.0 of the Joystick library. I tried to use version 2.0, but the Arduino IDE warns you that resources will be running low, and the 16u2 will simply brick :) So I had to flash HoodLoader2 again and restart from scratch. Maybe a crimped version of the 2.0 would work but I didn't test this.
  3. You have to write a small "communication bridge" program between the 16u2 and the AtMega328. It will simply get bytes (in a protocol you have to decide) from the AtMega328, and transform them in calls to the Joystick library.
  4. Write an arbitrary complex program on the AtMega328 that will allow you to have some complex behaviour, like button rebinding, autofire, and so on. The program will have to transform data so that the 16u2 will understand them.
  5. If you use Windows, it will see 2 controllers and you're done! If you use Linux, it will see the double controller as a single one, and you have to pass the correct parameter to the kernel, as documented by mr. Heironimus (the HID_QUIRK_MULTI_INPUT issue). But, as you have flashed the 16u2 with HoodLoader2, you have to change the Product ID with 0x484C. That is, add "usbhid.quirks=0x2341:0x484C:0x040" to /boot/cmdline.txt (I determined the value plugging the Mega under Window and checking it in the Control Panel).

I managed to plug such a modified version of the Mega to a Raspberry Pi 3 and Retropie sees it as a double controller, that actually works! :)

So, I'd like to thank mr. Heironimus and mr. Nico Hood for their work, and I hope that this post may help someone else.

Multiple Single Joysticks change enumeration order on windows

Not sure if "Issues" is the correct place for this but i wasnt finding a better place.

I have been working on a project that requires 4 "independent" joysticks in the system. Eventually I plan on moving to your Joystick3 class and extend it to 4 controllers though for now I would like to see if there is a way that i could get the 4 different joysticks ( Each different Leonardo + USB connection ) to enumerate in the same order each time.

I noticed in the Joystick2/3 there was a JOYSTICK2_REPORT_ID. Does that help control order of enumeration / allow windows to see each joystick as a different device and hopefully maintain enumeration or is there a better way you know of.

Worst case i think the joystick3 class will work ( once extended to 4 and adding some of the buttons back in ) but thought i would ask your opinion.

hid.h

I've copied the library file as instructed but getting an error saying the hid.h file cannot be found. Any ideas?

Games won't recognice my device

I've constructed a button box for my sim and I'm using your library but it's not working at all. Windows recognices the device as gaming controller but I can't bind any button to any game. This is my code.

#include <Joystick.h>

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_GAMEPAD, 19, 0, false, false, false, false, false, false, false, false, false, false, false);

int buttonPins[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, A0, A1, A2, A3, A4, A5};
int buttonPreviousState[] {LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW};

void setup() { 
    for(int i = 0; i < sizeof(buttonPins); i ++)
        pinMode(buttonPins[i], INPUT);

    Joystick.begin();
}

void loop() {
    buttonPreviousState[0] = pushButton(1, buttonPreviousState[0], 0);
    buttonPreviousState[1] = pushButton(2, buttonPreviousState[1], 1);
    buttonPreviousState[2] = pushButton(3, buttonPreviousState[2], 2);
    buttonPreviousState[3] = pushButton(4, buttonPreviousState[3], 3);
    buttonPreviousState[4] = pushButton(5, buttonPreviousState[4], 4);
    buttonPreviousState[5] = pushButton(6, buttonPreviousState[5], 5);
    buttonPreviousState[6] = pushButton(7, buttonPreviousState[6], 6);
    buttonPreviousState[7] = pushButton(8, buttonPreviousState[7], 7);
    buttonPreviousState[8] = pushButton(9, buttonPreviousState[8], 8);
    buttonPreviousState[9] = pushButton(10, buttonPreviousState[9], 9);
    buttonPreviousState[10] = pushButton(11, buttonPreviousState[10], 10);
    buttonPreviousState[11] = pushButton(12, buttonPreviousState[11], 11);
    buttonPreviousState[12] = pushButton(13, buttonPreviousState[12], 12);
    buttonPreviousState[13] = pushButton(A0, buttonPreviousState[13], 13);
    buttonPreviousState[14] = pushButton(A1, buttonPreviousState[14], 14);
    buttonPreviousState[15] = pushButton(A2, buttonPreviousState[15], 15);
    buttonPreviousState[16] = pushButton(A3, buttonPreviousState[16], 16);
    buttonPreviousState[17] = pushButton(A4, buttonPreviousState[17], 17);
    buttonPreviousState[18] = pushButton(A5, buttonPreviousState[18], 18);
}

int pushButton(int pin, int previousState, int button) {
    int currentState;

    currentState = digitalRead(pin);
  
    if(currentState != previousState) {
        Joystick.setButton(button, currentState);/*
        if(currentState == HIGH)
            Joystick.setButton(button, HI);
        else
            Joystick.setButton(button, currentState);*/
        
        delay(10);
    }

    return currentState;
}

Buttons are connected through resistor to arduino pins. I've tested with JOYSTICK_TYPE_GAMEPAD, JOYSTICK_TYPE_JOYSTICK and JOYSTICK_TYPE_MULTI_AXIS but it won't work anyway.

image

image

After running the test my computer wont find the device

I have an Arduino Leonardo and I downloaded the single joystick library. After putting the file in my libraries I ran the test, and it uploaded to my board fine, but when I go to devices to find my board its not there. So I opened my device manager and the board is showing up there, but still not in the devices. I have tried to unplug the board and plug it back in and reset the board, but nothing works. In the HID properties it says "Device started" "Device configured", and then it says "Device not migrated." I am using windows 10 i'm not sure if that matters. Please let me know if you can help me at all.

Reversed axis range cannot be defined

First thing first: this is not really an issue but more a request.

I was toying with the new library version and tried to reverse the axis behaviour. My starting code was this:

#include <Joystick.h>

//pure x axis...
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_JOYSTICK,
  0, 0,                  
  true, false, false,    
  false, false, false,   
  false, false,          
  false, false, false);  

int readPot;

void setup() {
 Joystick.begin();
 Joystick.setXAxisRange(0, 1023);
}

void loop() {
readPot = analogRead(A2);

 Joystick.setXAxis(readPot);
}

This code works flawlessy, but if you set a reversed XAxisRange:

Joystick.setXAxisRange(1023, 0);

It "doens't work": the axis cannot be controlled by the pot anymore.
I know that this could be "fixed" by a simple, standard, arduino "map" function, but it would be nice to reverse the axis by simply reverse the range definition :)

Keep the great work up!

Impossibility to create an 8-axis device

(Sorry I don´t speak english this is traslated with Google Tool)
Hi!
I can't create 8 axis joystick.
4 axis don't working.

My sketch:

#include <Joystick.h>
Joystick_ Joystick(
JOYSTICK_DEFAULT_REPORT_ID,
JOYSTICK_TYPE_JOYSTICK,
32,
2,
true, //Indicates if the X Axis is available on the joystick.
true, //Indicates if the Y Axis is available on the joystick.
true, //Indicates if the Z Axis (in some situations this is the right X Axis) is available on the joystick.
true, //Indicates if the X Axis Rotation is available on the joystick.
true, //Indicates if the Y Axis Rotation is available on the joystick.
true, //Indicates if the Z Axis Rotation is available on the joystick.
true, //Indicates if the Rudder is available on the joystick. //Don't work!
true, //Indicates if the Throttle is available on the joystick.
false, //Indicates if the Accelerator is available on the joystick. //Don't work!
false, //Indicates if the Brake is available on the joystick. //Don't work!
false); //Indicates if the Steering is available on the joystick. //Don't work!
void setup() {
Joystick.begin(); }
void loop() { }

Events not detected under SDL2

I have ran into it multiple times with this library (or previously with my home made equivalent).

SDL2 does detect a SDL_JOYDEVICEADDED but then no further SDL_JOYBUTTONDOWN is emitted.

It's reproductible with a minimal Arduino code pressing buttons and the following SDL code :

#include <SDL2/SDL.h>
#include <iostream>

int main(int argc, char **argv)
{
    // Notre fenêtre
    bool end = false;
    SDL_Joystick *joy;
    SDL_Event evenements;
    bool terminer(false);

    if(SDL_Init(SDL_INIT_VIDEO |SDL_INIT_JOYSTICK) < 0)
    {
        std::cout << "Error during SDL init : " << SDL_GetError() << std::endl;
        SDL_Quit();

        return -1;
    }
    SDL_JoystickEventState(SDL_ENABLE);
    for(int i=0;i<SDL_NumJoysticks();i++){
      std::cout<<"Joystick N°"<<i<<" : "<< SDL_JoystickNameForIndex(i) << std::endl;
    }
    while(!end){
      while(SDL_PollEvent(&evenements)) 
      {
        switch (evenements.type){
          case SDL_QUIT:
            /* Quit the application */
            std::cout<<"EXIT"<<std::endl;
            end = true;
            break;
          case SDL_CONTROLLERDEVICEADDED:
            std::cout<<"Controller Added"<<std::endl;
            break;
          case SDL_JOYDEVICEADDED:
            std::cout<<"Joystick Added"<<std::endl;
            break;
          case SDL_JOYBUTTONDOWN:
            std::cout<<"button "<<evenements.jbutton.button<< "Pressed"<<std::endl;
            break;
          default:
            std::cout<<"event of type:"<<evenements.type<<std::endl;
        }

      }
    }
    // On quitte la SDL
    SDL_Quit();

    return 0;
}

Compile with : g++ -lSDL2 SDL_test.cpp -o test

I've tested with debian 8.2 (SDL2 v2.0.2) and arduino Leonardo. I lack the hardware to do proper testing on other platforms / hardware.

I think it might just be a problem in SDL and I'm ready to dig into it but beforehand I'd like to be sure it's a global problem which affect "everyone".

It is possible change HID code of a axis?

I'm creating a Driving simulator, but there's no clutch at the library. I thought that changing de HID descriptor code at Joystick.cpp would resolve my problem, like change the:

	if (includeRudder == true) {
		// USAGE (Rudder)
		tempHidReportDescriptor[hidReportDescriptorSize++] = 0x09;
		tempHidReportDescriptor[hidReportDescriptorSize++] = 0xBA;
	}

to:

	if (includeRudder == true) {
		// USAGE (Rudder)
		tempHidReportDescriptor[hidReportDescriptorSize++] = 0x09;
		tempHidReportDescriptor[hidReportDescriptorSize++] = 0xC6;
	}

But this not work. The axis disappear:

clutch try

Anybody has some idea how to change it?

Thanks, Guilherme

Higher axis accuracy than -127 to 127? Say -512 to 512?

Arduinos analog ports are 10bit (zero and due are 12bit) so go from 0-1023, but this library only lets you use 8bit, 1/4 of the resolution, I'd really like an option to go higher resolution on one/more axis, 8bit isn't enough to make a precision joystick or similar.

Arduino DUE 1.6.11 not supported.

For some reason, I can not initialize the Joystick emulator using my Arduino DUE.

I am using Arduino IDE 1.6.11, and using Windows 10

Enhancement: Simplify the Joystick Constructor

As we add features to the Joystick library, the constructor method is getting unruly. Create a JoystickSetup or JoystickConfiguration structure that can be used as a single input parameter to the Joystick's constructor method.

windows 10 creators edition crash

hi I wonder if anyone knows why I can use sliders but as soon as I plug in usb and a button command is in the program not just pressed but used in the code. windows 10 crashes out. Instead of the usual plugged in sound keyboard goes dead (lights out) then a few seconds latter PC dies. btw my program works perfectly on windows 7, 4 sliders and 20 buttons

No Issue Just 2 Questions

Hi. Sorry i not found a Email Adress... So i use the issue section to reqeust for help !

First Thank you for this wonderfull code.... I´m pretty new with HID Controllers so i got 2 Questions.

  1. Multible HOLD Buttons.
    I want to use your System in a Flight Simulator.... There i need lots of NON Momenary Static Switches... that Means it remains PUSHED if it stay in ON Position.
    Is THIS a problem with your code when i need for example 15 Buttons on a Controller that ALL Pushed and stay ON same Time ? In other Words... Is there a limit how many buttons can be ON same time ?

  2. Combination of multible Arduinos.
    I Normlay work with Arduino Mega for other stuff like showing LED and Displays..... So i´m a bit confused about the verry low PIn Number on Ardunio Micro/Leonardo.
    You say we can work with 32 Buttons, Hat switches and so on.... But i not get enough Pins for all this stuff.
    Question: Is Every Arduino used as a single HID Gamecontroller or is it possible to combine for example 3 Micros so i set 20 Buttons on Controller 1 Hat switches on Controller 2 Axis on Controller 3 ... BUT All this is show as ONE Gamecontroller in Windows ??
    If i understand your readme..... Is it correct i can define a "ID Number" for the HID Device so i can set for example 3 Arduinos to the SAME HID Gamecontroller ??

Why i ask this..... The Number of Gamecontroller in my Flightsimulator Setup Area is limmited.... A Proffessional Hardware like LeoBodnar support 32 Buttons, Axis and all the stuff on ONE Device.
Im just a bit scarred if i would reach the limit pretty fast if i need to define a single GameControlelr Device for every Arduino if i only have so less pins.

Thank you ! And again sorry for posting this in wrong area !

Analog resolution

Hi,
is there a specific reason why the axis only go from -127 to 127? The resolution is rather low when compared to the possible 1024 steps from the ADC on the Arduino Leonardo.

Keyboard.h

I am trying to complete this project but I am unable to upload the sketch to my aruduino. It is saying that Keyboard.h is not there. I looked at the download and only see joystick.h under the SRC folder. Any ideas? How am I to fix this?

Changing pins in GamepadExample triggers up randomly

Hi, thanks for your work on this library - much appreciated!

I've recently bought an Arduino Leonardo just for this project (genuine one, not a clone, in case it matters) but I'm having some trouble changing the pins from GamepadExample.

If for example I just change pins 2 to 6 with pins 3 to 7, the emulated pad starts going bananas with up being randomly triggered (touching the Arduino makes it trigger more often). And that's with NOTHING connected to it! I'm kinda new to Arduino, so I might be missing something terribly straightforward.

The issue is only exacerbated by adding more buttons. Then it starts doing all kinds of funny stuffs (triggering button 0 repeatedly, going down-left like mad, etc). The only thing that seems to be working right is a vanilla GamepadExample - as soon as I change the pins, it goes totally nuts. Maybe my Arduino is faulty?

Thanks for your help!

Joystick2 and Joystick3 libraries only appear as single joystick

Hello,

When I use the Joystick2 library, it only appears as a single joystick with 2-axis and 32-buttons. The buttons assigned on the second joystick (Joystick[1]) show as the first joystick (Joystick[0]) button+16... ie- when pressing J2 btn 0 it sends as J1 btn16, J2 btn 4 sends J1 btn20.., etc.. The Joystick3 library does not register ANY joysticks.

I am using Ubuntu 15.04 and jstest-gtk for testing.

More OSX strangeness? hat switch set to 0, won't init?

I'm figuring out slowly how to replicate my favourite USB controllers using Arduino plus this very useful library (many thanks Matt!). Ran into three issues. I would have posted them as three separate issues but for some reason the github interface will not let me post any additional issues, so I'm editing this one.

  1. though Joystick lib is capable of creating a USB controller with 11 axes, OSX does not appear to recognise more than 8. I use JoystickShow (a minimal USB controller debug tool) to reveal all axes, hats and switches on attached devices. Even if I have enabled every axis in the Joystick device, OSX sees only axes 0 through 7. This is probably an OSX limitation so no action is possible other than an OS-specific note in the README.

  2. When I create a Multi Axis joystick instance with exactly one hat switch, for some reason that hat switch is pegged to the "up" position (0 degrees).
    I thought I had just not initialised it properly. So I added
    Joystick.setHatSwitch(0,JOYSTICK_HATSWITCH_RELEASE);
    per the doco. This was accepted by the compiler so I think there are no typos, but it had no effect on the hat switch, still pegged to the up or 0-deg position. I have not pursued this problem further because of the far more distressing issue #3, below:

  3. For some reason, as yet I have no idea why, there is some kind of crosstalk between the Joystick device and mouse movement on my OSX machine. When I drive X axis or Z axis, and I assume Y does this also, my mouse pointer travels up and left and gets pinned in the upper left hand corner of the screen. Moreover, even after I have returned the axis value to zero, the mouse is still trying to rush off the upper left corner of the screen. The only way I can get it back is to reset the Leonardo running the Joystick sketch. After a reset all is well until the very first write to the Joystick axis, after which the mouse pointer goes mad again. I have changed the USB HID number thinking that it might be conflicting with the other Leonardo (mouse and keyboard control): changed it from Default to 0x4 hoping this would stop the mouse hijack. So far no luck.

Here are the relevant snippets of the code. Basically it receives a number over i2c from another Leonardo (also a USB HID, but Keyboard/Mouse type) and uses this value to set a Joystick device axis value. I can see the axis value changing using JoystickShow app, but I have no idea why mouse control is being hijacked; particularly I don't understand why the mouse continues to go nuts after the axis value returns to zero. The mad mouse behaviour did not happen when I used a default instantiation "Joystick_ Joystick;"

Am I doing something stupid?

#include <Joystick.h>
// Create the Joystick
Joystick_ Joystick(0x04, 
  JOYSTICK_TYPE_MULTI_AXIS, 12, 0,
  true, true, true, false, false, false,
  false, false, false, false, false);
// create a multi axis controller that looks just exactly like a driving force gt
// with three axes 0 1 2, a hat (removed because it's pegged at 0 deg), and a bunch of buttons
// looks fine in JoystickShow
(...)
(in setup:)
 Wire.begin(8);                // join i2c bus with address #8
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(9600);           // start serial for output
  Joystick.begin();
  delay(100);
  Joystick.setZAxisRange(0,255);
(...)
(in loop:)
   Joystick.setZAxis(tval);

[update] SOLUTION to item 3: the device type cannot be MULTI_AXIS, at least not in OSX. Even though JoystickShow seems to see both options as identical, if I use JOYSTICK_TYPE_JOYSTICK instead of JOYSTICK_TYPE_MULTI_AXIS the mouse hijacking problem goes away -- and zowie, I can finally get a commercial game to see the xaxis input from my arduino setup. The problem of the hat pegged at zero, however, remains. I will investigate that further as soon as I have some time.

Arduino Zero compatiblity ?

Is it possible to port it so that is can also be compatible with the SAMD21 based board ?
I tried a bit myself but I'm not good enough to do it.
Upon compilation I get "Joystick.h is missing", and when I try to place the .h and .cpp next to the .ino my the Arduino IDE found invalid lib and my board goes berzerk.
So I guess that this part of the HID isn't yet written for the Arduino Zero, or that it does not support this part of the HID ?

Incompatibility with Keyboard.h

I have not tested much and don't really know what is causing it.
I wanted my Leonardo to be both a joystick and a keyboard.
As soon as I added the #include <Keyboard.h> my mouse cursor was controlled by the values I was sending to the X and Y axes of the Joystick.
I don't even have to call Keyboard.begin().
Also, the the Leonardo wasn't recognized as a joystick anymore, I think.

My guess is that some HID-magic is going wrong between the two libraries, so the values get sent as mouse axes instead of joystick axes.

Probably reproducible by running the following code:

#include <Keyboard.h>
#include <Joystick.h>

void setup() {
  Joystick.begin();
}

void loop() { //should move joystick stick in a square really fast
  Joystick.setXAxis(-5);
  Joystick.setYAxis(-5);
  Joystick.setXAxis(5);
  Joystick.setYAxis(5); 
}

How can I increase the axis range to 1024

That's great job man! Thank you very much!

I need 1024 resolution or more for XYZ axis, I try to change descriptor report and use 16bit value, but that also dosn't work.

0x15, 0x00,                         //   LOGICAL_MINIMUM (0)
0x27, 0xFF, 0xFF, 0x00, 0x00,      //   LOGICAL_MAXIMUM (65535)
0x75, 0x10,                        //   REPORT_SIZE (16) 

and changed 8 bit to 16 bit
int16_t xAxis;
void Joystick_::setXAxis(int16_t value) also in Joystick.h and Joystick.cpp

uint16_t data[JOYSTICK_STATE_SIZE];

There was no feedback in windows joystick setting. What's wrong with my code?

Thanks again!

Second joystick not recognized by OS

Thanks for this awesome library!
I managed to run it smoothely when only defining one joystick.
When I setup a second one, the OS doesn't see it: it only registers /dev/input/js0 and no js1.
Here's the minimal test code:

#include <Joystick.h>

Joystick_ Joy1(0x03, JOYSTICK_TYPE_JOYSTICK, 2, 0, true, true, false, false, false, false, false, false, false, false, false);
Joystick_ Joy2(0x04, JOYSTICK_TYPE_JOYSTICK, 2, 0, true, true, false, false, false, false, false, false, false, false, false);

void setup() {
  Joy1.begin();
  Joy2.begin();
}

and dmesg output:

[ 7397.746824] input: Arduino LLC Arduino Micro as /devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.2/0003:2341:8037.0011/input/input32
[ 7397.747064] hid-generic 0003:2341:8037.0011: input,hidraw2: USB HID v1.01 Joystick [Arduino LLC Arduino Micro] on usb-0000:00:14.0-3/input2

OSX only sees one joystick. But all Axis' & buttons

I'm using a Pro Mini clone (still using a ATMega34U - https://www.amazon.co.uk/gp/product/B019SXN84E/ref=oh_aui_detailpage_o01_s00?ie=UTF8&psc=1 ), in case that has any bearing;

I have implemented multiple joysticks on one arduino, with multiple buttons, multiple axis';
On Windows these show up as separate joysticks (all working)
On OSX (Sierra) the HID system sees 1 joystick, with all the axis' and buttons present (and working)
Tested with unity and an app from the MacApp store; "Controllers Lite"

Any idea where this could be going wrong? Maybe OSX has some quirks with the USB-HID protocol?

Untested on linux (although plugging into an android phone showed 1 joystick, but I can't vouch for the test apps I was using, and they may only support one joystick anyway)

'Joystick' was not declared in this scope

Hi!

Forgive if I seem to be stupid. I´m totally new to this and have no programming skills at all.

Every time I try to verify and compile any of the joystick sketches I get the error message" 'Joystick' was not declared in this scope ". I´m using Win 10 and Arduino 1.6.6 default installation version 1 of sketch templates. Version 2 with the sketch templates gives " 'Joystick_' does not name a type " error. I´ve also tried it on an Win 7, same IDE version with the same result. If I remove the parts of the analog joystick, povhats and axis, which I don´t need, I still end up with the same result. Any help would be appreciated

/Fredrik
capture

Error

Hi,
when I import the joystick library, I get the following error:

Arduino: 1.7.9 (Windows 8.1), Board: "Arduino Leonardo"

In file included from sketch_apr19b.ino:1:0:

C:\Program Files (x86)\Arduino\libraries\Joystick/Joystick.h:24:17: fatal error: HID.h: No such file or directory

#include "HID.h"

             ^

compilation terminated.

Error compiling.
_

I get that even if I only import the library. Any ideas of why that happens?

Thanks!

HTML5 Gamepad compability

Hi MHeironimus,
thank you for this very easy to use and straightforward library.

This is probably more of a question than an issue, I hope you don't mind.

I've successfully used you library, when testing my 1-axis joystick (a Leonardo with a b10k pot) in Win 7 everything works perfect. It register -127 to 127 and goes edge to edge.

But here's the issue, it does not work properly as a HTML5 Gamepad. According to the HTML5 spec it expect axis value range from -1 to 1. I was under the impression that this range conversion would be handled by the browser but it seems the browser receives the -127 to 127 values.
Gampad API tester
HTML5 Gamepad Tester

Do you, or any one else of course, have any idea how to approach this to make the joystick comply to the HTML5 specs?

I have the question on stackoverflow.

Invalid library found in

I think there is a new requirement of Arduino IDE 1.8.2 for Libraries. We get this warning/info when compiling "Invalid library found in Drive://Path"

i got wrong value in unity

hello .. MHerionimus..
i love your adrduinoJoystickLibraray

i test axis in the version 2.0.2 with arduino leonard
i got correct value in DIView, but it's wrong in unity 5.5..
i need to map 0 ~ 1023 to 512 ~ 1023, then i got correct value in unity..
i cant figure out what happen....
could you help me?

is it possible to Rename the HID Controller

Hi,
i´d like to connect 4 Arduino-gamepads to my PC and my Raspberrry.
is it possible to change the HID name?
so that i don´t have:
arduino leonardo
arduino leonardo
arduino leonardo
arduino leonardo

but my own names?

'Joystick' was not declared in this scope

#Hello,

I'm a complete novice to arduino programming and was wondering if anyone had any idea of why I am getting this error? I was trying to use a joystick for my laptop and wanted to try learn something productive in the summer off from university.

Thanks in advance

// Program used to test the USB Joystick object on the
// Arduino Leonardo or Arduino Micro.
//
// Matthew Heironimus
// 2015-03-28
// Updated on 2015-11-18 to use the new Joystick library written for version 1.6.6.
//------------------------------------------------------------

#include "Joystick.h"

// Set to true to test "Auto Send" mode or false to test "Manual Send" mode.
//const bool testAutoSendMode = true;
const bool testAutoSendMode = false;

const unsigned long gcCycleDelta = 1000;
const unsigned long gcAnalogDelta = 25;
const unsigned long gcButtonDelta = 500;
unsigned long gNextTime = 0;
unsigned int gCurrentStep = 0;

void testSingleButtonPush(unsigned int button)
{
if (button > 0)
{
Joystick.releaseButton(button - 1);
}
if (button < 32)
{
Joystick.pressButton(button);
}
}

void testMultiButtonPush(unsigned int currentStep)
{
for (int button = 0; button < 32; button++)
{
if ((currentStep == 0) || (currentStep == 2))
{
if ((button % 2) == 0)
{
Joystick.pressButton(button);
} else if (currentStep != 2)
{
Joystick.releaseButton(button);
}
} // if ((currentStep == 0) || (currentStep == 2))
if ((currentStep == 1) || (currentStep == 2))
{
if ((button % 2) != 0)
{
Joystick.pressButton(button);
} else if (currentStep != 2)
{
Joystick.releaseButton(button);
}
} // if ((currentStep == 1) || (currentStep == 2))
if (currentStep == 3)
{
Joystick.releaseButton(button);
} // if (currentStep == 3)
} // for (int button = 0; button < 32; button++)
}

void testXYAxis(unsigned int currentStep)
{
if (currentStep < 256)
{
Joystick.setXAxis(currentStep - 127);
Joystick.setYAxis(-127);
}
else if (currentStep < 512)
{
Joystick.setYAxis(currentStep - 256 - 127);
}
else if (currentStep < 768)
{
Joystick.setXAxis(128 - (currentStep - 512));
}
else if (currentStep < 1024)
{
Joystick.setYAxis(128 - (currentStep - 768));
}
else if (currentStep < 1024 + 128)
{
Joystick.setXAxis(currentStep - 1024 - 127);
Joystick.setYAxis(currentStep - 1024 - 127);
}
}

void testZAxis(unsigned int currentStep)
{
if (currentStep < 128)
{
Joystick.setZAxis(-currentStep);
}
else if (currentStep < 256 + 128)
{
Joystick.setZAxis(currentStep - 128 - 127);
}
else if (currentStep < 256 + 128 + 127)
{
Joystick.setZAxis(127 - (currentStep - 383));
}
}

void testHatSwitch(unsigned int currentStep)
{
if (currentStep < 8)
{
Joystick.setHatSwitch(0, currentStep * 45);
}
else if (currentStep == 8)
{
Joystick.setHatSwitch(0, -1);
}
else if (currentStep < 17)
{
Joystick.setHatSwitch(1, (currentStep - 9) * 45);
}
else if (currentStep == 17)
{
Joystick.setHatSwitch(1, -1);
}
else if (currentStep == 18)
{
Joystick.setHatSwitch(0, 0);
Joystick.setHatSwitch(1, 0);
}
else if (currentStep < 27)
{
Joystick.setHatSwitch(0, (currentStep - 18) * 45);
Joystick.setHatSwitch(1, (8 - (currentStep - 18)) * 45);
}
else if (currentStep == 27)
{
Joystick.setHatSwitch(0, -1);
Joystick.setHatSwitch(1, -1);
}
}

void testThrottleRudder(unsigned int value)
{
Joystick.setThrottle(value);
Joystick.setRudder(255 - value);
}

void testXYAxisRotation(unsigned int degree)
{
Joystick.setXAxisRotation(degree);
Joystick.setYAxisRotation(360 - degree);
}

void setup() {
if (testAutoSendMode)
{
Joystick.begin();
}
else
{
Joystick.begin(false);
}

pinMode(A0, INPUT_PULLUP);
pinMode(13, OUTPUT);
}

void loop() {

// System Disabled
if (digitalRead(A0) != 0)
{
digitalWrite(13, 0);
return;
}

// Turn indicator light on.
digitalWrite(13, 1);

if (millis() >= gNextTime)
{

if (gCurrentStep < 33)
{
  gNextTime = millis() + gcButtonDelta;
  testSingleButtonPush(gCurrentStep);
} 
else if (gCurrentStep < 37)
{
  gNextTime = millis() + gcButtonDelta;
  testMultiButtonPush(gCurrentStep - 33);
}
else if (gCurrentStep < (37 + 256))
{
  gNextTime = millis() + gcAnalogDelta;
  testThrottleRudder(gCurrentStep - 37);
}
else if (gCurrentStep < (37 + 256 + 1024 + 128))
{
  gNextTime = millis() + gcAnalogDelta;
  testXYAxis(gCurrentStep - (37 + 256));
}
else if (gCurrentStep < (37 + 256 + 1024 + 128 + 510))
{
  gNextTime = millis() + gcAnalogDelta;
  testZAxis(gCurrentStep - (37 + 256 + 1024 + 128));
}
else if (gCurrentStep < (37 + 256 + 1024 + 128 + 510 + 28))
{
  gNextTime = millis() + gcButtonDelta;
  testHatSwitch(gCurrentStep - (37 + 256 + 1024 + 128 + 510));
}
else if (gCurrentStep < (37 + 256 + 1024 + 128 + 510 + 28 + 360))
{
  gNextTime = millis() + gcAnalogDelta;
  testXYAxisRotation(gCurrentStep - (37 + 256 + 1024 + 128 + 510 + 28));
}

if (testAutoSendMode == false)
{
  Joystick.sendState();
}

gCurrentStep++;
if (gCurrentStep == (37 + 256 + 1024 + 128 + 510 + 28 + 360))
{
  gNextTime = millis() + gcCycleDelta;
  gCurrentStep = 0;
}

}
}

Android A/B/X/Y button mappings

Could you add the possibility to press button A/B/X/Y on android gamepad?

The mappings of this joystick are arround 188 (index 0) and higher.. the button mappings for standard android buttons are;
A: 96
B: 97
X: 99
y: 100
RT: 103
LT: 102
TR: 107
TL: 106
Start: 108
Volume: 183
Back: 4

This button mappings are taken from NVIDIA Shield Portable and should be working for most of the Android Gamepads

How to get 16bit precision?

How do we set Arduino Micro to get use of 16bit precision while micro's analog pins can only provide 10bits?

LGPL / GPL ?

Hello,

Thanks for writing this code, it's really handy. Looking through it I noticed a license conflict: in the root of the repository the LICENSE file says that the license is GPL, but each of the source files have a header that indicates the license to be LGPL. I wonder which is the license that you intend?

Various questions...

  • can i configure more than 32 buttons?, changed in joystick.h to 64 buttons, but only showed 32 in joystick properties
  • In Joystick properties, not show "Rudder", "Throttle", "Brakes" and "Steering"

Thanks....

A gamepad support

Hello,

I want to make from my Arduino Pro Micro (Atmega32u4) to a gamepad (2 axis thumb joystick) and some buttons. Any ideas or documentations of gamepad HID?

Thanks

Feature request: Force Feedback/Rumble/Vibration support

I’d like to request support for Force Feedback/Rumble/Vibration (controller motor control). I’ve seen that other albeit old ATmega32U4 projects have implemented this, for example
https://github.com/tloimu/adapt-ffb-joy/blob/wiki/USBFfbHid.md
Ideally this would appear as a joystick with advanced force feedback features in a Windows machine without need for installing any device drivers like the above project.
Assuming this is possible I think it would be a welcome addition to an already great library, what do you think?

edit 2019-04
Hoping this might be of interest to people following this feature request. David Madison has recently started the Arduino XInput Library https://github.com/dmadison/ArduinoXInput, using XInput allows for reading of rumble motors!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.