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.07k stars 403 forks source link

[FIXED] Read proper pot values #179

Closed V3nom536 closed 3 years ago

V3nom536 commented 3 years ago

Hi, im sorry for changing the topic question but i solved my old problem so i maybe can ask a new one. I assigned the xaxis to a pot which acts like a tiller wheel for my flight sim but i have a huge dead zone and it start steering almost at the end of pot's range, can it be fixed somehow? Thanks for any advice! Heres my pot related section of code: int XAxis = analogRead(A8); //reads input from A8 pin Serial.println(XAxis); //REMOVE AFTER TESTING XAxis = map(XAxis, 0, 1023, 255, 0); //map the xaxis variable Joystick.setXAxis(XAxis_); //move the axis in the virtual joystick [EDIT] Got my problem fixed by adding a response curve in flight sim settings.

ttait-vantim commented 3 years ago

How did you wire the pot up? What value is it? Is it linear or log (audio) curve?

Tim

V3nom536 commented 3 years ago

linear pot with pin 1 connected to vcc, pin 3 to gnd and pin 2 to analog input but as said, i got it fixed by adding a response curve in the flight sim

ttait-vantim commented 3 years ago

So it the issue is resolved? You should probaby close this ticket then.

Still I'm not sure why you need to adjust the response in the flight sim, did the ADC readings look normal and linear?

Did you set the scale for the joystick channel range in setup()? ie: Joystick.setXAxisRange(0, 1023);

I'm not sure what map is, I didn't need to use it for my throttle quadrant.

Tim

V3nom536 commented 3 years ago

The values look perfect, set the range (0, 1023, 255, 0) in setup and everything seems fine but in the sim most of the pot range wasnt moving the tiller at all. It was nearly required to move full left or full right to give an input, after i set the response curve in the exact point the pot was starting to "generate input" then the calibration was perfect and i got full pot's range working

ConBeeUser commented 3 years ago

The values look perfect, set the range (0, 1023, 255, 0) in setup and everything seems fine but in the sim most of the pot range wasnt moving the tiller at all. It was nearly required to move full left or full right to give an input, after i set the response curve in the exact point the pot was starting to "generate input" then the calibration was perfect and i got full pot's range working

I bet this is relatet to using the map-function. You map the range of 0-1023 to 255-0 which means that the scale is inverted and reduced to a quarter of its full length. I think you should try removing map or as I did first: map(0, 1023, 0, 1023);

which of cource is useless (as it maps e.g. a read value of 750 to 750 but you can quickly revert it this way.

If your max read value of 1023 just moves the in game value by about a quarter of the available slider, this might be the reason.

Cheers Mat