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
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