Delaying process

Dear all,

I wanted to know how to delay a process without affecting main code.

#include <MsTimer2.h>


int Analog_Pin=5;
int newaverage;
float Output_Current;
#define RELAY1  7
#define MAX_TRIP_COUNT  5
float Current_Limit=0.6;
static int Trip_Count=0;
static int Tripped_Flag=1;
int Serial_Status=0;



void TakeReading()
{
  newaverage = analogRead(A5);
  
//  Serial.print("newaverage:");
  //Serial.println(newaverage);
  Output_Current = 0.0336666666667*newaverage - 17.17; 
}


void Chk_Relay_Tripped()
{
  if(Output_Current>=Current_Limit)
  {
    Trip_Count=Trip_Count+1; 
    if((Trip_Count>=MAX_TRIP_COUNT) &&(Serial_Status==0))
    {

      Trip_Count=0;
      
  MsTimer2::set(30000, Relay_Activate); // 500ms period
  MsTimer2::start();
     // Relay_Activate();
    }
    else
      if(Serial_Status==1)
      {
        Serial.println("> MODE");
        Relay_Deactivate(); 
      }

  } 
  else
  {
    Trip_Count=Trip_Count-1;
    if(Trip_Count<0)
    {
      Trip_Count=0;
    }

    if(Trip_Count<MAX_TRIP_COUNT && Serial_Status==1)
    {
      Relay_Deactivate();
      Serial_Status=0;
    }

  }

}




void Relay_Activate()
{
   // MsTimer2::stop();
   
   for (unsigned long start = millis(); millis() - start < 10000;)
  {
    digitalWrite(RELAY1,HIGH);
    Serial_Status=1;
  }
   
    digitalWrite(RELAY1,HIGH);
    Serial_Status=1;
  
}

void  Relay_Deactivate()
{
  digitalWrite(RELAY1,LOW);
 // Serial_Status=0;
}

void Relay_Intialize()
{
  digitalWrite(RELAY1,LOW);
}

void setup() {
  Serial.begin(9600); // set serial speed
  pinMode(RELAY1, OUTPUT); // set LED as output
  //digitalWrite(RELAY1, LOW); //turn off LED

  pinMode(Analog_Pin,INPUT);
  Relay_Intialize();
}




void loop(){
  TakeReading();
  Chk_Relay_Tripped();
  Serial.println(Output_Current);
   //while (Serial.available() == 0); // do nothing if nothing sent
  int val = Serial.read() - '0';
  if (val == 1) { // test for command 1 then turn on LED
    Serial.println("RELAY on");
    digitalWrite(RELAY1, LOW); // turn on LED
    Serial_Status=1;

  }
  else if (val == 0) // test for command 0 then turn off LED
  {
    Serial.println("RELAY OFF");
    digitalWrite(RELAY1, HIGH); // turn off LED
    Serial_Status=0;
  }
  delay(500);
}

In below code , In below function It will wait for 30S to execute once 30s elapsed other thing s will be printed. But i wanted to print even in 30s . What need to change in below code.

void Relay_Activate()
{
  for (unsigned long start = millis(); millis() - start <30000;)
  {
    digitalWrite(RELAY1,HIGH);
    Serial_Status=1;
  }

}

I wanted to know how to delay a process without affecting main code.

There is ONLY one process, so talk of a process separate from the main code is meaningless.

In below function It will wait for 30S to execute

No, it doesn't. It TAKES 30 seconds to execute - mostly doing nothing.

I wanted to know how to delay a process without affecting main code.

Let us all intone the mantra
"Look at blink without delay, without delay. Ommmmm"

look to call the delayed function like this, untested:

turns on a relay after 30 seconds and back on after 5.

if (something) // start the timer
{
  startTime = millis(); // start time, a global unsigned long
}
relay_Activate(30000UL,5000UL);

where 30000UL is the time you want the delayed action to begin

void Relay_Activate(unsigned long delayTime, unsigned long duration)
{
  static boolean printed = false;
  if (millis() - startTime <= delayTime)
  {
    // do nothing
  }
  else if (millis() - startTime <= delayTime + duration)
  {
    if (!printed)
    {
      digitalWrite(RELAY1, HIGH);
      Serial_Status = 1;
      printed = true;
    }
  }
  else
  {
    digitalWrite(RELAY1, LOW);
    Serial_Status = 0;
    printed = false;
  }
  //never reset the startTime in the loop
}

Thanks for support . solved.