Analog inputs working differently

Hello guys.
I have tryed to replace an old joystick board (not working) for an Arduino Leonardo board.

I have 6 potenciometers B10k.

My code is this below:

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_GAMEPAD, 14, 0,
  false, false, false, true,true, false,
  false, false, true, true, true);

void setup() {

  Joystick.setAcceleratorRange(0, 1023);
  Joystick.setBrakeRange(0, 1023);
  Joystick.setRxAxisRange (0, 1023);
  Joystick.setRyAxisRange (0, 1023);
  Joystick.setSteeringRange(0, 1023);
  
  
    Joystick.begin();   
}

void loop() {

Joystick.setRyAxis (analogRead(A4));
Joystick.setAccelerator (analogRead(A2));
Joystick.setRxAxis (analogRead(A1));
Joystick.setSteering (analogRead(A0));
Joystick.setBrake (analogRead(A3));

}

A2, A3 and A4 are working nicelly.

A0 works partially. When I scroll the potentiometer in your full range, the computer shows working just half range (50%). it just works between 50% and 100%. Does not show values between 0% and 50%.

A1 is working full range of values, but it get 100% of range when I scrolled just 30% of potenciometer, causing and out of scale results. As A0, I changed the potenciometer for a working potenciometer (A2 for example), getting the same results (out of scale).

Last question: I would like to add the A5 analog, to the last potentiometer. According the documentation (GitHub - 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.), I tryed to add others axis names, but always get the message error: "Compilation error: no matching function for call to 'Joystick_::setXAxisRange(int)".

I appreciate your support.

TKS Guys.
Best Regards.

Hi @fellipezambrano.

You must pass two arguments to the setXAxisRange function: the minimum and the maximum. The error occurred because you only passed one argument to the function. The function works just the same as the functions like setRxAxisRange that you are already using in your sketch:

So just study the code to learn how to use the library correctly.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.