Need little help with this code

Robin2:
if this was my program I would have one function to read and save the values from all the I/O pins once per iteration of loop() and I would use those values in all the code used in that iteration.

Hi
thanks for pointing me this..

i move all variables like ''boolean'' at the first of sketch to be Global
Also i removed all the statements from the beging of each scope like the one you told me ''digitalRead(stop_check); ''

but i had to leave all the others inside the ''while'' and ''do while'' loops so can read if is any change in the conditions of the loop

of course the problem continues to ... when returns for ''void timeError()'' functions goes to ''void loop()'' and then continues in the '' void Run_Test() '' without press again the button to call this function

if the program returns from any other function it stays in ''void loop()'' normally...

Here is the code with the changes in variables :

byte lock_check = 13; // input pin to check lock-doors
byte contact_check = 14; // input pin to check contacts-doors
byte stop_check = 9; // input pin to check stop
byte end_limits = 2; // input pin to check end limits
byte relayLeft = 10; //the relay that drives left the car
byte relayRight = 11;//the relay that drives right the car
byte slowDownVVF = 12; // Pin to drive vvf voltage via transistor (slow speed)
byte electromagnet = 15; //the relay that drives up the electromagnet of doorslocks
byte call_button = 3; //pin to call to floor test for timelimits  test
byte rstMvButton = 4;  // reset time error in movement
unsigned long intervalMotor = 3000;  // maximum working time
unsigned long previousMillisMotor;

bool callflag = false;

boolean contacts;
boolean doorLocks;
boolean carStop;
boolean limitsStop;
boolean controlMaintain;
boolean carMaintain;
boolean calling;
boolean resetMove;

void setup() {


  Serial.begin(9600);

  // initialize the digital pins inputs.

  pinMode(contact_check, INPUT_PULLUP);
  pinMode(lock_check, INPUT_PULLUP);
  pinMode(stop_check, INPUT_PULLUP);
  pinMode(end_limits, INPUT_PULLUP);
  pinMode(call_button, INPUT_PULLUP);
  pinMode(rstMvButton, INPUT_PULLUP);

  // initialize the digital pins outputs.
  pinMode(relayRight, OUTPUT);
  pinMode(relayLeft, OUTPUT);
  pinMode(slowDownVVF, OUTPUT);
  pinMode(electromagnet, OUTPUT);

}

void loop() {


  contacts = digitalRead(contact_check);
  doorLocks = digitalRead(lock_check);
  carStop = digitalRead(stop_check);
  limitsStop = digitalRead(end_limits);
  calling = digitalRead(call_button);

  if (calling == false && callflag == false) {

    if (contacts == false && carStop == false && limitsStop == false) {
      callflag = true;
      Run_Test();
    }
  }
  if (contacts == false && carStop == false && limitsStop == false) {

    Serial.println(" Everything ok - Standby ");
  }

  if (carStop == true) {

    Serial.println(" Reads stop ");
  }

  if (contacts == true || carStop == true || limitsStop == true) {
    digitalWrite(relayRight, LOW); //keep the relay for right motion inactive
    digitalWrite(relayLeft, LOW); //keep the relay for left motion inactive
    digitalWrite(slowDownVVF, LOW); //keep the VVF running with high speed quite
    digitalWrite(electromagnet, LOW); //keep the relay for electromagnet inactive
  }

  if (carStop == true || limitsStop == true ) {
    stop_car();
  }

}

void Run_Test() {

  previousMillisMotor = millis();


  if (contacts == false  && carStop == false && limitsStop == false ) {
    do
    {

      callflag = false;
      doorLocks = digitalRead(lock_check);
      carStop = digitalRead(stop_check);
      limitsStop = digitalRead(end_limits);
      contacts = digitalRead(contact_check);
      digitalWrite(relayRight, HIGH);

      Serial.println(" Going to position ");

      if (millis() - previousMillisMotor >= intervalMotor)
      {

        timeError();

      }

    }

    while ( contacts == false && carStop == false && limitsStop == false);

  }

}


void stop_car() {

  while (carStop == true ) {

    boolean carStop;
    carStop = digitalRead(stop_check);
    digitalWrite(relayRight, LOW); //keep the relay for right motion inactive
    digitalWrite(relayLeft, LOW); //keep the relay for left motion inactive
    digitalWrite(slowDownVVF, LOW); //keep the VVF running with high speed quite
    digitalWrite(electromagnet, LOW); //keep the relay for electromagnet inactive
    Serial.println("Stop is Active");
    if (carStop == !true ) {
      break;
    }

  }

  while (limitsStop == true ) {

    boolean limitsStop;
    limitsStop = digitalRead(end_limits);
    digitalWrite(relayRight, LOW); //keep the relay for right motion inactive
    digitalWrite(relayLeft, LOW); //keep the relay for left motion inactive
    digitalWrite(slowDownVVF, LOW); //keep the VVF running with high speed quite
    digitalWrite(electromagnet, LOW); //keep the relay for electromagnet inactive
    Serial.println("end limits are on");
    if (limitsStop == !true ) {
      break;
    }

  }

}


void timeError()  {

  resetMove = digitalRead(rstMvButton);
  previousMillisMotor = millis();

  do {

    resetMove = digitalRead(rstMvButton);
    Serial.println("To Late - Time Limit");

    if (resetMove == false ) {
      Serial.println("Reads resetbutton");

      break;
    }

  } while (resetMove == true);

  loop();
}