Blynk and time lapse need help

Hi, I made an Arduino program that controls my camera to make time lapse.
this program has 3 buttons to adjust the interval of photos … and lcd and a photovoltaic to stop at night

and 2 led, a green signify that all is well and a red led mean that there is a problem.
now i want to try to connect my program with the internet via esp8266 and arduino mega.
my problem is that i do not able to conect blynk with my old program, to control my camera remotely and change the shooting setting…the connection is not stable .and I can t control the buttons via aplication blynk.

here is a part of my program:::

void loop(){

  
   while (mode == 0){
   
  
    lcd.print("interval en sec");
    while (mode == 0){
      lcd.setCursor(0,1);
      lcd.print(((interval/1000)));
      
      lcd.setCursor(9,1);
      lcd.print(((interval/1000))/60);
      
      delay(100);
      button1_state = !digitalRead(button1); // read state of Button 1
  button2_state = !digitalRead(button2); // read state of Button 2
button3_state = !digitalRead(button3); // read state of Button 3
      if (button1_state==true) {
        interval = interval+1000;
      } 
       if (button3_state==true) {
        interval = interval+60000;
      } 
      if (button2_state== true){
        mode = 1;
        
        lcd.clear();
        delay(500);
      } 
    } 
  }

  //////////////////////// CONFIRM INTERVAL ////////////////////////
  //   Press Button 1 to go back or Press Button 2 to Confirm     //
  //////////////////////////////////////////////////////////////////

  while (mode == 1){

    lcd.print("Mon interval");
    lcd.setCursor(0,1);
    
    lcd.print(interval/1000);
   
    
  
    lcd.setCursor(9,1);
    lcd.print("OK?");
    delay(50);

    while ( mode == 1){
      button1_state = !digitalRead(button1); // read state of Button 1
  button2_state = !digitalRead(button2); // read state of Button 2

      if (button1_state == true){
        mode = 0;
        interval = interval+100;
        
        lcd.clear();
        delay(500);
      }
      if (button2_state == true){
        mode = 3;
        interval = interval-700;
        lcd.clear();
        delay(500);
      }
    } 
  }


  /////////////////////////// SET AMOUNT /////////////////////////////
  // Press&Hold Button 1 to increase Amount, Confirm with Button 2  //
  ////////////////////////////////////////////////////////////////////

  while (mode == 3){
    lcd.print("Prise de vue");
    while (mode == 3){
      lcd.setCursor(0,1);
      lcd.print(pics);
      delay(50);
      button1_state = !digitalRead(button1); // read state of Button 1
  button2_state = !digitalRead(button2); // read state of Button 2
 button3_state = !digitalRead(button3); // read state of Button 3
      if (button1_state==true) {
        pics++;
      } 
      if (button3_state==true) {
        pics=pics+100;
       // hona kanat maktouba bihada chakl  pics--
        
      } 
      if (button2_state== true){
        mode = 4;
        lcd.clear();
        delay(500);
      } 
    } 
  }

  ///////////////////////// CONFIRM AMOUNT /////////////////////////
  //   Press Button 1 to go back or Press Button 2 to Confirm     //
  //////////////////////////////////////////////////////////////////

  while (mode == 4){

    lcd.print("Prise de vue");
    lcd.setCursor(0,1);
    lcd.print(pics); 
    lcd.setCursor(5,1);
    lcd.print("OK?");
    delay(50);

    while ( mode == 4){
  button1_state = !digitalRead(button1); // read state of Button 1
  button2_state = !digitalRead(button2); // read state of Button 2

      if (button1_state == true){
        mode = 3;
        pics = 0;
        lcd.clear();
        delay(500);
      }
      if (button2_state == true){
        mode = 5;
        lcd.clear();
        delay(500);
      }
    } 
  }


  //////////////////// WAIT TO START SEQUENCE //////////////////////
  //                Countdown to start Sequence                   //
  //////////////////////////////////////////////////////////////////

  while (mode == 5){
    lcd.write("Depart"); 
    for (int k = 3 ; k>0; k--){
      lcd.setCursor(1,1);
      lcd.print(k);
      delay(1000);
    }
    Serial.print(interval);
    mode =6;
    lcd.clear();
    lcd.print("Shooting");
  } 




  /////////////////////// SHOOTING SEQUENCE ////////////////////////
  //   Press Button 1 to go back or Press Button 2 to Confirm     //
  //////////////////////////////////////////////////////////////////

  while (mode == 6)
  {{digitalWrite(focus, HIGH);
 delay(200);
 digitalWrite(focus, LOW);
 delay(2000);
lightLevel = analogRead(lightPin);
lightLevel = map(lightLevel, 0, 900, 0, 255);
lightLevel = constrain(lightLevel, 0, 255);
analogWrite(ledPin, lightLevel);



 {
  val = digitalRead(ledPin);
{val2= digitalRead(ledAlert);



    

if (val == LOW)

{digitalWrite(ledAlert , HIGH);
lcd.clear();
lcd.print("boitier en panne");
lcd.setCursor(0,1);
    lcd.print("send msg");}


else
  
  {
    digitalWrite(ledAlert , LOW);
     lcd.clear();
    lcd.setCursor(0,1);
    lcd.print((pics*(interval+700)/1000/60));                                  
    lcd.setCursor(8,1);
    lcd.print ((pics*(interval+700)/1000/60/60));
    lcd.setCursor(14,1);                                                      
   lcd.print(((pics*(interval+700)/1000/60/60))/24);
   lcd.setCursor(8,0);/////////////////////////////////////////////////////////////////////////////////////////////////
   lcd.print(interval/1000);
    digitalWrite(focus, HIGH);    // turn focus on
    delay(focus_on);              // keep focus
    digitalWrite(focus, LOW);     // turn focus off
    delay(wait);                  //wait
    digitalWrite(shutter, HIGH);  //press the shutter
    digitalWrite(led,HIGH);        //turn on status led
    delay(shutter_on);            //wait the shutter release time
    digitalWrite(shutter, LOW);    //turn of status led
    digitalWrite(led,LOW);        //release shutter
    pics--; 
    lcd.setCursor(0,0);
    lcd.print(pics);
   delay(interval);
   
   
                

    if (pics == 0) {
      mode=7;
      lcd.clear();
      lcd.print("c fini....");
     
    
  }
 

  
  }}}}}}}}

is there a way for this part of my program to work in a loop at the same time as blynk too?

think you and I apologize for my bad english.

Take some time to understand BLYNK, and how to utilize timers.

Also, you would be best to avoid while loops.

Blynk is not just a simple add-in GUI library… it is an full IoT interface with portions operating in the background… So you will need to radically redesign any “normal” Arduino code that runs mostly in the void loop() to one that has a clean void loop() and uses timed functions to make up the now-to-be-avoided delay() and while() commands as they are blocking (AKA stops ALL processing or allowing of other processes until designated criteria is met) and will cause your IoT device to become an unstable and disconnected device.

As mentioned, it is best to start small with Blynk examples until you understand how it fundamentally works, then you can work on porting your existing code over.

PS, I fixed your post to properly format your posted code for forum viewing… please look over how it is to be done in the future, thanks.

Blynk - FTFC

thank you for your answer.I am sucking in the brogram. can you explain to me how to avoid the fanction whille and replace it with another fanction that does not block my programe.I will be happy if someone can modify my program and add timer instead of the whill and delay functions. thank you so much

Already explained in the documentation links provided above.

PS, we are not code mechanics… we try to help you learn, not do it for you.