Compared to what you describe, it is not the position of the joystick that is important, but its direction. It is therefore sufficient to compare the current value with the previous one to deduce the direction, and taking into account the sign of values.
The only problem is that a joystick has progressive values, calculate between the center and the edge. By doing what you want, there will no longer be progressivity. For when you are right to the maximum and you go left, what value should be the joystick?
So we are on a system on OFF 1 or 0, I go left, or I go right, but not I go slowly to the left etc ..