Reading analog values but value is not "centered"

I am reading an analog value from a 4 axis joystick ( 4-As Plastic Joystick Potentiometer Voor JH-D400X-R4 10K 4D Met Knop Draad # Aug.26 - AliExpress).
The joystick all the way to the left gives me analog value 15, the joystick all the way to the right gives me 1023.

I mapped the value with this line:

int joystick1YAxis        = map(analogRead(JOYSTICK_1_Y_AXIS), 15, 1023, 1023, 0);

But when the joystick is in the middle position, i don't get value 512, or 519, but i get 623.
Is there a good way to correct this value?

Subtract an offset. The map function won't give you the expected middle value.

I did that as a test, but than i am subtracting also from the min value. Is that the correct way to do?

Please post the code, your explanation is unclear.

My code is here:

int joystick1YAxis        = map(analogRead(JOYSTICK_1_Y_AXIS), 15, 1023, 1023, 0);

This is the code to get the analog value.
But i get values from 15 to 1023. I should expect a value of 519 when the joystick is in idle position, but i get 623.

My question is how to correct this value in code so 623 should be converted to 623, but variable so that other values will be corrected dynamically

You can decide that numbers around 623 correspond to the idle position and write the program accordingly.

There is nothing special about 519.

I see a screw next to the the pot of the joystick.
If you loosen that a bit, then you can turn the pot body until the A/D outputs ~512.
Leo..

So you need to record the following output values by moving the joystick in full range and centering it. Use these values as variables in your program.

Minimumvalue 6
Centervalue 623
Maximumvalue 1008

If output value is less than the center value, map from minimumvalue to centervalue mapped to 0 to 511

If output is >= to your center value, map from centervalue to maximumvalue mapped to 512 to 1023

You should probably clamp the finalvalue between 0 and 1023

This means you will use the full range of the joystick

As an added benefit, if you wanted to add some trim to the joystick center, you can just adjust the center value up or down

Another thing you can do is add a deadzone. If you had a deadzone of 5, check if your final value is between 512 - 5 and 512 + 5. If it is, then set your final value to be 512

You are right, i completely missed this.
Thank you!