MHeironimus / ArduinoJoystickLibrary

An Arduino library that adds one or more joysticks to the list of HID devices an Arduino Leonardo or Arduino Micro can support.
GNU Lesser General Public License v3.0
2.1k stars 409 forks source link

Remove the axes #107

Closed Katoz96 closed 4 years ago

Katoz96 commented 5 years ago

Hi,

I built a handbrake for my simulator using an Arduino ProMicro on Windows 10 following this tutorial.

This is the code included in the tutorial

#include <Joystick.h>

void setup()

{
  pinMode(A1, INPUT); 
  Joystick.begin();
}

const int pinToButtonMap = A1;

void loop()

{
  int pot = analogRead(A1);
  int mapped = map(pot,0,1023,0,255);
  {Joystick.setThrottle(mapped);}
}

Everything works fine but the Z axis it's stuck at 50% even after calibrating it, in some games it's not a problem but in others it makes them unplayable.

arduinoleonardo At first I wanted to ask how to solve this problem but then it occurred to me that it would be nice to have only one axis for the handbrake.

So, it's possible to remove everything else (including the buttons) and leave only one axis?

Thanks in advance

MHeironimus commented 5 years ago

If you use the latest version of the library, you can control what features are presented to the host computer. See https://github.com/MHeironimus/ArduinoJoystickLibrary#joystick_ for more details.

Katoz96 commented 5 years ago

Thanks, I have updated the library, I have modified the code and now everything seems to work perfectly.

Here is the code, if someone had the same problem:

#include <Joystick.h>

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_GAMEPAD,
  0, 0,                        // Button Count, Hat Switch Count
  false, false, false,    // X, Y, Z 
  false, false, false,    // Rx, Ry, Rz
  false, true,              // rudder, throttle
  false, false, false);   // accelerator, brake, steering

void setup()

{
  pinMode(A1, INPUT); 
  Joystick.begin();
}

const int pinToButtonMap = A1;

void loop()

{
  int pot = analogRead(A1);
  int mapped = map(pot,0,1023,0,255);
  Joystick.setThrottle(mapped);
}

One last thing, I don't understand if const int pinToButtonMap = A1; it's useless and I can remove it and what exactly does int mapped = map(pot,0,1023,0,255);