DC motor with 3(or more) programmed limits

Yes I already use a H bridge to move the motor instead of relays. The encoder was mounted on the geared shaft of the motor. The encoder was 360/rev. Ordinary chinese.

I try to do next:

void extendActuator() {

analogWrite(RELAY[0], 200);
analogWrite(RELAY[1], 0);
}

void retractActuator() {

analogWrite(RELAY[0], 0);
analogWrite(RELAY[1],100); //digitalWrite(RELAY[1], HIGH);
}

void stopActuator() {

analogWrite(RELAY[0],0);
analogWrite(RELAY[1], 0);
}

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.

It was be good if we split the MANUAL from AUTOMATIC and be able to set up speed separately. Also if I set up PWM in AUTOMATIC, it is working all the time with one setted PWM.

I think it is also a good solution if we do the job with only 2 PWM. To start with 255 and finish with 50(for example). The garage door motors do the same. Working with 2 voltage. 24 and 12VDC.

The question is how can I define where is the switching point between the fast and the slow motion.?

A