PeterH:
Your logic to decide which way to move the motor (and how fast) looks very strange. I'd expect you to decide what the desired position was based on the joystick, compare that with the actual position to determine how far the motor was from the desired position and in which direction, and determine the motor speed and direction from that. Instead you're just comparing the motor and joystick positions against some limits. Presumably this means that the motor is just supposed to go between two fixed positions rather than follow the joystick. Could you clarify what behaviour you're aiming for?The technique of setting the motor speed and then waiting for a second before you do anything else pretty much guarantys that the motor will overshoot. If I were you I'd do the position comparison as fast as possible and decide what direction/speed you want the motor to move, tell it to move in that direction / speed and then immediately do the position comparison again etc.
the code part is really simple, I just control the motor's direction with the h - bridge (joystick signal, right or left), and I use the pot signal like to limit. now I'm searching about PID (I`m Mech Engineer but automatization is not my strength) I realize improved as had recomendade (control P) but how can I figure out the constant (Kp) to do like you say speed = (desired position - actual position)*Kp
