rc receiver - Arduino - servo

Hello,
I am very new here and at all with arduino. To learn more I started a little project. The idea is - that controll my boat manually with radio and also it should have a little “autopilot”.
The “manually mode” - receiver send pulseIn to arduino and arduino to servo or ESC(In my code it is CH1 and CH3). Everything works well!
Now when I will to turn on autopilot with CH5 - Everything works well!
But when I will turn it off with the same CH5 it doesent work. The autopilot code is still working and I cant control it manually.
What I need to change in the code to have ability turn on and off the “autopilot” with CH5?
So maybe you can give me the right tipp? Thanks!
To run the code you will need VarSpeedServo http://rapidshare.com/files/425318464/VarSpeedServo.zip libraries.

#include <VarSpeedServo.h> 
 
VarSpeedServo rudder;  // create servo object to control a servo 
VarSpeedServo throttle;
int CH1=0;  // analog pin used to connect the potentiometer
int CH3=0;
int CH5=0;
int val;    // variable to read the value from the analog pin 
int autopilot=0;
void setup() 
{ 
 pinMode(13, OUTPUT); 
 pinMode (8, INPUT);  // CH1
 pinMode (9, INPUT);  // CH3
 pinMode (7, INPUT); // CH5
 rudder.attach(11);  // Rudder
 throttle.attach(12);  // Throttle
 throttle.slowmove (55, 0);           //  THROTTLE CONTROL (CH3)
 delay(5000);                        //  ESC START UP
 CH5 = (pulseIn (7, HIGH, 100000))/10;

} 

void loop() 
// MANUAL MODE
{ 
if(CH5 < 100){
digitalWrite(13, HIGH);
CH1 = (pulseIn (8, HIGH, 100000))/10;
val = (CH1);             
val = map(val, 185, 107, 20, 160);     // scale it to use it with the servo (value between 0 and 180) 
rudder.slowmove (val, 0);   

CH3 = (pulseIn (9, HIGH, 100000))/10;
val = (CH3);             
val = map(val, 109, 180, 54, 130);     // scale it to use it with the servo (value between 0 and 180) 
throttle.slowmove (val, 0);   
} 

// AUTO MODE
CH5 = (pulseIn (7, HIGH, 100000))/10;
if (CH5 > 100)
{
digitalWrite(13, LOW);

rudder.slowmove (90, 0);
throttle.slowmove (100, 30);             // maxRPM 130 // minRPM 58 // stop 55
delay(10000);

throttle.slowmove (60, 0);
rudder.slowmove (20, 0);   
delay(1000);
throttle.slowmove (70, 10);
rudder.slowmove (90, 10);
delay(2000);

throttle.slowmove (55, 0);
rudder.slowmove (90, 10);
delay(30000);
}



}

All those delay()s are killing you. If you get a pulse to turn "auto" mode on, you don't look for a pulse to turn it off for 42 seconds. All kinds of issues could take place in that 42 seconds.

So what should I do?

You have a state machine, no? Auto is one state, manual is another state.

Within the auto state you have states - the comments don't describe them but they appear to be - lots of throttle, straight - little throttle, hard turn - little more throttle, straight - very little throttle, straight

Use millis() to determine when a state change occurred. Record that time.

On every pass through loop, see whether there is a need to transition to another state immediately (got input). See if it is time to transition to another state, because you've been in the current state long enough. If it is time to transition, make whatever changes are needed - throttle, rudder, state, and/or time.

Look at the blink without delay example, without delay.