constrain ,, wil this be in the hole sketch or also in parts ,,

i ask this because i use some constrain for my throttle ,, but when i switch to a other mode it stil use the constrain used in the sketch ,

i post the sketch , and i mean in the below part ,, one constrain
this is the one sys = constrain(system,1000,1725); ,,,
this one i onley need in the part its in , but it seems to run true the hole sketch ,,
:roll_eyes:

// dexters KK2.0 automatic flight system //
// debug sketch 5-8-2014 // 

#include <Servo.h> 
#include <NewPing.h> 
#define TRIGGER_PIN  3  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     2  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 600 // max sensor value 400 means 4 meter 
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
// set height here //
const int height =6000; // is digital value for height 
const int auxset =1800; // aux output to kk2.0 for setting auto level onboard on or off !
const int decent =400; // decent delay time this is the hard part depents on survace and height set //
// the above values need to be tuned //
int cm ; //incoming value of sensor 0-100000
int sensor;// sensor cm values in centimeter 
int safety =1; // safety switch value//
int auxv ; // Here's where we'll keep our aux channel values 1400 < autolevel off 1400 > = on
int auxs ; // Here i store input aux to servo output numbers  
int throtv ; // Here's where we'll keep our throttle channel values
int throts ; // Here i store  input throttle to servo output numbers 
int system ; // system for do stuf with throttle and height //
int mem1; 
int sys;
int led = 13;
int piezo = 10;
// gimbal to horizontal and vertical pos readout //
// normal when start flying on the kk 2.0 the gimbal wil center its pos if used right //
int horim ; // using this for boxing the horizontal value from kk2.0
int horiz ;
Servo throttle;  // make servo output to kk2.0 throttle input
Servo aux;       // make servo output to kk2.0 aux input
int signal =0; // signal procces 

void setup() {
  Serial.begin(57600); // starting serial port for APC220 wireles tx rx baud rate 57600  
  aux.attach(7);   // servo conection out pin 7 to kk2.0 aux input //
  throttle.attach(8); // servo conection out pin 8 to kk2.0 throttle input //
  aux.writeMicroseconds(auxset);   // set aux output to autolevel on on kk2.0 //
  pinMode(led, OUTPUT);
  pinMode(piezo,OUTPUT);
  pinMode(4, INPUT); // NEW HORIZ INPUT CHANNEL 
  pinMode(5, INPUT); // Set input channel for aux on pin 5 from rx //
  pinMode(6, INPUT); // Set input channel for throttle on pin 6 from rx //
  pinMode(9, INPUT); // Set input channel from gimbal horizontal pin 9 from rx for reading level //
  pinMode(10, INPUT); // Set input channel from gimbal vertical pin 10 from rx for reading level //
  // some indication light or piezo 
  digitalWrite(led, LOW);   // turn the LED on 
  digitalWrite(piezo, LOW);   // turn the PIEZO on 
  delay(1000);               // wait for a second
  digitalWrite(led, HIGH);   // turn the LED on 
  digitalWrite(piezo, HIGH);   // turn the PIEZO on 
  delay(1000);               // wait for a second
  digitalWrite(led, LOW); 
  //  
  system = 0;
  throtv = pulseIn(6, HIGH, 20000); //checking throttle input from rx
  auxv = pulseIn(5, HIGH, 20000); //checking throttle input from rx 
  if (throtv > 1025){ // if throttle is higher then 1025 then safety goes first //
    throttle.writeMicroseconds(1000); // throttle on 0 before start 
    delay (1000);  
    safety =1; // safety wil be fase 1 = disable trhottle input , and output 0 throttle  = disabled mode //
    return;
  }
  else if (throtv < 1025)
  {
    safety =2; // if input throttle = near 0 then safety wil be fase 2 = working quadcopter going to safety fase 3 later = flight mode //
  }
}
void loop() {
  sensor = cm/ US_ROUNDTRIP_CM;
  Serial.flush();
  Serial.print((char)1); 
  Serial.print (throts);
  Serial.print((char)2);
  Serial.print (throtv);
  Serial.print((char)3);
  Serial.print (height);
  Serial.print((char)4);
  Serial.print (auxv);
  Serial.print((char)5);
  Serial.print (auxset);
  Serial.print((char)6);
  Serial.print (cm); 
  Serial.print((char)7);
  Serial.print (sensor);
  Serial.print((char)8); 
  Serial.print (safety); 
  Serial.print((char)9); 
  Serial.print (horiz);
  Serial.print((char)10);
  Serial.print (0);
  Serial.print((char)11);
  Serial.print (decent);
  Serial.flush();
  // vertm = pulseIn(10, HIGH, 20000); //checking gimbal vertical  input 
  horim = pulseIn(4, HIGH, 20000); //checking gimbal horizontal input 
  throtv = pulseIn(6, HIGH, 20000); //checking throttle input
  auxv = pulseIn(5, HIGH, 20000); //checking throttle input
  horiz =map(horim, 1600, 1400,100,0);
  cm = sonar.ping();
  if (safety ==1){ // checking startup safety fase ,if fase = 1 then throttle wil be 0 and wil loop till reset button //
    delay (3000);
    return;
  }
  aux.writeMicroseconds(auxset);  // aux ON for autolevel kk2.0 conected to aux input //
  throtv = pulseIn(6, HIGH, 20000); //checking throttle input pwm
  auxv = pulseIn(5, HIGH, 20000); // Read the pulse width of AUX input on pin 5 and reads input pwm//
  if (auxv<1300){
    digitalWrite(led, HIGH);  
    system =throtv ; // telling the system the value of the throtle input 
    throttle.writeMicroseconds(throtv);  // write system speed to servo //  
    // if aux is off the input throttle = equal to input // 
    sys =throtv;
  }
  mem1 =sys;
  if(height<cm){ // if sensor is lower then height value // 
    system = sys -1;// take speed DOWN by 1 digit of the system // 
    throts = mem1;
    sys = constrain(system,1000,2000);
    throttle.writeMicroseconds(sys);  // write system speed to servo //
    delay (decent);
  }
  if(height>cm){ // if sensor is lower then height value //     
    system = sys +4  ;// take speed up by 4 digit of the system // 
    throts = mem1; 
    sys = constrain(system,1000,1725);
    throttle.writeMicroseconds(sys);  // write system speed to servo // 
  }
}

this is the one sys = constrain(system,1000,1725); ,,,

Return the input value if it is between the lower and upper limit. Otherwise return the lower limit if the value is below the lower limit or return the upper limit if the value is above the upper limit.

You store that value in a different variable. What is the problem? The value of system is not affected by the constrain() function.

yes ,, i explain ,, i have 2 modes ,, one it wil write incoming straight to outgoing ,, this dont need a constrain ,,
the incoming wil be between 1000 and 2000 ,,
when i switch to mode 2 ,, it wil use the constrain when it is on that part of the sketch ,,
it wil count up till the contrain 1730 ,,
when i switch back ,, i can see and also read it on my GUI ,,
that my input is like 1800 , but my output is constrained to 1730 ,,
most strange thing is i not constrain the input or the output ,, i onley constrain the system value to the sys value ,,
and not the .. first part ,, when it reads input on throtv = pulseIn(6, HIGH, 20000) and write this straight out
throttle.writeMicroseconds(throtv); there is no constrain on this , but it is doing so
i see this when i fly my quadcopter ,, and on my read out ,,
strange
. butt maybe its easy to use ,, if x> 2000 x=2000 , saves calculation time ,,