DC motor with 3(or more) programmed limits

Brinarpi:
The motor is turning only in extend way. If I move retract back to digitalWrite it is working again. In extend with PWM, in retract with high speed. Also in MANUAL mode do the same.

This suggests to me that you need to go ALL THE WAY back to basics and just write a short program that moves the motor at medium speed in one direction for a few seconds and then in the other direction.

As you have not posted a link to the datasheet for your H-bridge I cannot suggest the details for that code but the overall style would be like this

void loop() {

   analogWrite(motorReversePin,0);
   analogWrite(motorForwardPin, 100);
   delay(1000);

   analogWrite(motorForwardPin, 0);
   analogWrite(motorReversePin, 100);
   delay(1000);
}

Then you can experiment to find the range of speeds that you want to use.

And also experiment to count the pulses from the encoder and identify the motor direction

...R