Terminal input, error when save value input

I am making a tool using the input value of the user, the input is the value of drinking times for example 1, 2,3,4 for each terminal. the value is stored in the SaveArray [] array. with the code as below and successfully stores input values ​​from the user (as shown below). code below I have added the void program () function that I have not previously entered

/*************************************************************
 * Project: string inpu untuk mengtur jam minum obat
 */

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <TimeLib.h>
#include <WidgetRTC.h>


//Widget yang digunakan
BlynkTimer timer;
WidgetRTC rtc;
WidgetLED led1(V4);

//milis() pengganti delay
#define interval_message 10000
unsigned long time_1 = 0;


// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "***********************************";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "****************************************";
char pass[] = "***************************************";

// Attach virtual serial Pil_1 to Virtual Pin V1
WidgetTerminal terminal(V11);
WidgetTerminal Pil_1(V5);
WidgetTerminal Pil_2(V6);
WidgetTerminal Pil_3(V7);
WidgetTerminal Pil_4(V8);
WidgetTerminal Pil_5(V9);
WidgetTerminal Pil_6(V10);

//count untuk timer
unsigned count = 0;

//Save input on array
int SaveArray[8];
int nilai[5];
int button[2];

// You can send commands from Pil_1 to your hardware. Just use
// the same Virtual Pin as your Pil_1 Widget
BLYNK_WRITE(V5)
{
  if (String("1") == param.asStr()) {
    Pil_1.println("Minum 1x1");
    SaveArray[1]=1;
  }
  
    else if (String("2") == param.asStr()) {
    Pil_1.println("Minum 2x1");
    SaveArray[1]=2;
  }
  
    else if (String("3") == param.asStr()) {
    Pil_1.println("Minum 3x1");
    SaveArray[1]=3;
  }
  
    else if (String("4") == param.asStr()) {
    Pil_1.println("Minum 4x1");
    SaveArray[1]=4;
  }

    else if (String("5") == param.asStr()) {
    Pil_1.println("Minum 5x1");
    SaveArray[1]=5;
  } else {
    // Send it back
    Pil_1.print("You said:");
    Pil_1.write(param.getBuffer(), param.getLength());
    Pil_1.println("Fix your Time input") ;
    Pil_1.println();
  }
  // Ensure everything is sent
  Pil_1.flush();
}


// You can send commands from Pil_1 to your hardware. Just use
// the same Virtual Pin as your Pil_1 Widget
BLYNK_WRITE(V6)
{
  if (String("1") == param.asStr()) {
    Pil_2.println("Minum 1x1");
    SaveArray[2]=1;
  }
  
    else if (String("2") == param.asStr()) {
    Pil_2.println("Minum 2x1");
    SaveArray[2]=2;
  }
  
    else if (String("3") == param.asStr()) {
    Pil_2.println("Minum 3x1");
    SaveArray[2]=3;
  }
  
    else if (String("4") == param.asStr()) {
    Pil_2.println("Minum 4x1");
    SaveArray[2]=4;
  }

    else if (String("5") == param.asStr()) {
    Pil_2.println("Minum 5x1");
    SaveArray[2]=5;
  } else {
    // Send it back
    Pil_2.print("You said:");
    Pil_2.write(param.getBuffer(), param.getLength());
    Pil_2.println("Fix your Time input") ;
    Pil_2.println();
  }
  // Ensure everything is sent
  Pil_2.flush();
}


// You can send commands from Pil_1 to your hardware. Just use
// the same Virtual Pin as your Pil_1 Widget
BLYNK_WRITE(V7)
{
  if (String("1") == param.asStr()) {
    Pil_3.println("Minum 1x1");
    SaveArray[3]=1;
  }
  
    else if (String("2") == param.asStr()) {
    Pil_3.println("Minum 2x1");
    SaveArray[3]=2;
  }
  
    else if (String("3") == param.asStr()) {
    Pil_3.println("Minum 3x1");
    SaveArray[3]=3;
  }
  
    else if (String("4") == param.asStr()) {
    Pil_3.println("Minum 4x1");
    SaveArray[3]=4;
  }

    else if (String("5") == param.asStr()) {
    Pil_3.println("Minum 5x1");
    SaveArray[3]=5;
  } else {
    // Send it back
    Pil_3.print("You said:");
    Pil_3.write(param.getBuffer(), param.getLength());
    Pil_3.println("Fix your Time input") ;
    Pil_3.println();
  }
  // Ensure everything is sent
  Pil_3.flush();
}


// You can send commands from Pil_4 to your hardware. Just use
// the same Virtual Pin as your Pil_3 Widget
BLYNK_WRITE(V8)
{
  if (String("1") == param.asStr()) {
    Pil_4.println("Minum 1x1");
    SaveArray[4]=1;
  }
  
    else if (String("2") == param.asStr()) {
    Pil_4.println("Minum 2x1") ;
    SaveArray[4]=2;
  }
  
    else if (String("3") == param.asStr()) {
    Pil_4.println("Minum 3x1");
    SaveArray[4]=3;
  }
  
    else if (String("4") == param.asStr()) {
    Pil_4.println("Minum 4x1") ;
    SaveArray[4]=4;
  }

    else if (String("5") == param.asStr()) {
    Pil_4.println("Minum 5x1") ;
    SaveArray[4]=5;
  } else {
    // Send it back
    Pil_4.print("You said:");
    Pil_4.write(param.getBuffer(), param.getLength());
    Pil_4.println("Fix your Time input") ;
    Pil_4.println();
  }
  // Ensure everything is sent
  Pil_4.flush();
}


// You can send commands from Pil_5 to your hardware. Just use
// the same Virtual Pin as your Pil_5 Widget
BLYNK_WRITE(V9)
{
  if (String("1") == param.asStr()) {
    Pil_5.println("Minum 1x1") ;
    SaveArray[5]=1;
  }
  
    else if (String("2") == param.asStr()) {
    Pil_5.println("Minum 2x1") ;
    SaveArray[5]=2;
  }
  
    else if (String("3") == param.asStr()) {
    Pil_5.println("Minum 3x1") ;
    SaveArray[5]=3;
  }
  
    else if (String("4") == param.asStr()) {
    Pil_5.println("Minum 4x1") ;
    SaveArray[5]=4;
  }

    else if (String("5") == param.asStr()) {
    Pil_5.println("Minum 5x1") ;
    SaveArray[5]=5;
  } else {
    // Send it back
    Pil_5.print("You said:");
    Pil_5.write(param.getBuffer(), param.getLength());
    Pil_5.println("Fix your Time input") ;
    Pil_5.println();
  }
  // Ensure everything is sent
  Pil_5.flush();
}


// You can send commands from Pil_5 to your hardware. Just use
// the same Virtual Pin as your Pil_5 Widget
BLYNK_WRITE(V10)
{
  if (String("1") == param.asStr()) {
    Pil_6.println("Minum 1x1") ;
    SaveArray[6]=1;
  }
  
    else if (String("2") == param.asStr()) {
    Pil_6.println("Minum 2x1") ;
    SaveArray[6]=2;
  }
  
    else if (String("3") == param.asStr()) {
    Pil_6.println("Minum 3x1") ;
    SaveArray[6]=3;
  }
  
    else if (String("4") == param.asStr()) {
    Pil_6.println("Minum 4x1") ;
    SaveArray[6]=4;
  }

    else if (String("5") == param.asStr()) {
    Pil_6.println("Minum 5x1") ;
    SaveArray[6]=5;
  } else {
    // Send it back
    Pil_6.print("You said:");
    Pil_6.write(param.getBuffer(), param.getLength());
    Pil_6.println("Fix your Time input") ;
    Pil_6.println();
  }
  // Ensure everything is sent
  Pil_6.flush();
}


//debug dengan push button virtual port 12
BLYNK_WRITE(V12) 
{
  if(param.asInt()==HIGH)
  {
    Serial.println("button on");
    button[1]=1;
  }else
  {
    Serial.println("button off");
    button[1]=0;
  } 
}



// Digital clock display of the time
void clockDisplay()
{
  // You can call hour(), minute(), ... at any time
  // Please see Time library examples for details

  String currentTime = String(hour()) + ":" + minute() + ":" + second();
  String currentDate = String(day()) + " " + month() + " " + year();
  Serial.print("Current time: ");
  Serial.print(currentTime);
  Serial.print(" ");
  Serial.print(currentDate);
  Serial.println();

  // Send time to the App
  Blynk.virtualWrite(V1, currentTime);
  // Send date to the App
  Blynk.virtualWrite(V2, currentDate);
}


BLYNK_CONNECTED() {
  // Synchronize time on connection
  rtc.begin();

  //Synchronize all widget on connection
  Blynk.syncAll();
}

void CekOutput()
{
   for(int i=1;i<=6;i++)
  {
    Serial.print("Nilai di pil ");Serial.print(i);Serial.print(" :");Serial.println(SaveArray[i]);
  }
    Serial.println("");Serial.println("");Serial.println("");
    
}

void Program()
{ 
 // int i=3;
  for(int i=1;i<=6;i++)
  {  //cek_box:
    //simpan nilai SaveArray pada Variable nilai
    nilai[i]=SaveArray[i];
    Serial.print("Cek Kotak ke-");Serial.println(i);
    //Serial.println(SaveArray[i]);
    
    //Program Switch untuk membandingkan nilai waktu
    switch (nilai[i]) {
    case 1:
          cek_box1:
          //minum 1 kali
          Serial.println("Minum obat 1 kali");
     
          // while(Berat(n+1) == Berat(n))//cek obat sudah diambil atau belum
          if(button[1] == 0)//cek obat sudah diambil atau belum
          {  
            satu:
            if(hour()==6)
            {
              if(minute()==1)//ketika jam 6 lebih 2 detik
                {
                if(millis()>time_1+interval_message)
                  {
                    time_1=millis();
                    //nyalakan Buzzer
                    Serial.println("Nyalakan Buzzer");
                    //digitalWrite(buzzer, HIGH);delay(10000); //nyalakan Buzzer 10 detik
                    //digitalWrite(buzzer, LOW); //Matikan Buzzer 10 detik

                    //fungsi gerakkan stepper
                    Serial.print("putar Stepper ke kotak ");Serial.println(i);
                    //stepper.setSpeed(4); // gerakkan Stepper dengan kecepatan 4 rpm
                    //stepper.step(255); // buka kotak (Lakukan 255 langkah)--sesuai dengan satu revolusi dalam satu menit
                  }//goto satu;
                }

              if(minute()==5)//menit ke 5
                { 
                if(millis()>time_1+interval_message)
                  {
                    time_1=millis();
                    //nyalakan Buzzer
                    Serial.println("Nyalakan Buzzer, peringatan 5 menit");
                    //digitalWrite(buzzer, HIGH);delay(10000); //nyalakan Buzzer 10 detik
                    //digitalWrite(buzzer, LOW); //Matikan Buzzer 10 detik
                  } //goto satu;
                }        

              if(minute()==59)//menit ke 59
                {
                if(millis()>time_1+interval_message)
                  {
                    time_1=millis();
                    //nyalakan Buzzer
                    Serial.println("Nyalakan Buzzer, peringatan 59 menit");
                    //digitalWrite(buzzer, HIGH);delay(10000); //nyalakan Buzzer 10 detik
                    //digitalWrite(buzzer, LOW); //Matikan Buzzer 10 detik

                    //kirim email
                    Serial.println("Kirim email notifikasi belum minum obat");
                  }//goto satu;
                }
                else
                { 
                if(millis()>time_1+interval_message)
                  {
                    time_1=millis();
                    //Kotak stay membuka di kotak 1
                    Serial.print("sekarang jam :");Serial.print(hour());Serial.print(" ");
                    Serial.println("Jam Sesuai, kotak membuka menunggu notif berikutnya, dan obat belum diminum");
              
                  }//goto satu;
                }
            }
            else{
                 if(millis()>time_1+interval_message)
                 {
                    time_1=millis();
                    //Kotak_Close( kotak obat menutup ke awal(home)
                    Serial.println("kotak close(home) bukan waktu minum obat dan tidak ada alarm apapun");
            
                 }//goto cek_box1;
                }
         }
         else{
              if(millis()>time_1+interval_message)
                {
                  time_1=millis();
                  //Cek nilai kotak berikutnya
                  //kirim email
                  Serial.print("obat kotak ke ");Serial.print(i);Serial.print(" sudah diminum ");
                  Serial.print("Cek nilai kotak berikutnya yang ke ");Serial.println(i+1);
                  ////goto sini;
                }
              }
              
      button[1]=0;
      Serial.println(button[1]);  
      break;
       
    case 2:
          cek_box2:
          //minum 1 kali
          Serial.println("Minum obat 2 kali");
     
          // while(Berat(n+1) == Berat(n))//cek obat sudah diambil atau belum
          if(button[1] == 0)//cek obat sudah diambil atau belum
          {  
            dua:
            if(hour()==6 || hour()==18)
            {
              if(minute()==1)//ketika jam 6 lebih 2 detik
                {
                if(millis()>time_1+interval_message)
                  {
                    time_1=millis();
                    //nyalakan Buzzer
                    Serial.println("Nyalakan Buzzer");
                    //digitalWrite(buzzer, HIGH);delay(10000); //nyalakan Buzzer 10 detik
                    //digitalWrite(buzzer, LOW); //Matikan Buzzer 10 detik

                    //fungsi gerakkan stepper
                    Serial.print("putar Stepper ke kotak ");Serial.println(i);
                    //stepper.setSpeed(4); // gerakkan Stepper dengan kecepatan 4 rpm
                    //stepper.step(255); // buka kotak (Lakukan 255 langkah)--sesuai dengan satu revolusi dalam satu menit
                  }//goto dua;
                }

              if(minute()==5)//menit ke 5
                { 
                if(millis()>time_1+interval_message)
                  {
                    time_1=millis();
                    //nyalakan Buzzer
                    Serial.println("Nyalakan Buzzer, peringatan 5 menit");
                    //digitalWrite(buzzer, HIGH);delay(10000); //nyalakan Buzzer 10 detik
                    //digitalWrite(buzzer, LOW); //Matikan Buzzer 10 detik
                  } //goto dua;
                }        

              if(minute()==59)//menit ke 59
                {
                if(millis()>time_1+interval_message)
                  {
                    time_1=millis();
                    //nyalakan Buzzer
                    Serial.println("Nyalakan Buzzer, peringatan 59 menit");
                    //digitalWrite(buzzer, HIGH);delay(10000); //nyalakan Buzzer 10 detik
                    //digitalWrite(buzzer, LOW); //Matikan Buzzer 10 detik

                    //kirim email
                    Serial.println("Kirim email notifikasi belum minum obat");
                  }//goto dua;
                }
                else
                { 
                if(millis()>time_1+interval_message)
                  {
                    time_1=millis();
                    //Kotak stay membuka di kotak 1
                    Serial.print("sekarang jam :");Serial.print(hour());Serial.print(" ");
                    Serial.println("Jam Sesuai, kotak membuka menunggu notif berikutnya, dan obat belum diminum");
              
                  }//goto dua;
                }
            }
            else{
                 if(millis()>time_1+interval_message)
                 {
                    time_1=millis();
                    //Kotak_Close( kotak obat menutup ke awal(home)
                    Serial.println("kotak close(home) bukan waktu minum obat dan tidak ada alarm apapun");
            
                 }//goto cek_box2;
                }
         }
         else{
              if(millis()>time_1+interval_message)
                {
                  time_1=millis();
                  //Cek nilai kotak berikutnya
                  //kirim email
                  Serial.print("obat kotak ke ");Serial.print(i);Serial.print(" sudah diminum ");
                  Serial.print("Cek nilai kotak berikutnya yang ke ");Serial.println(i+1);
                  ////goto sini;
                }
              }
              
      button[1]=0;
      Serial.println(button[1]);  
      break;

  case 3:
          cek_box3:
          //minum 1 kali
          Serial.println("Minum obat 2 kali");
     
          // while(Berat(n+1) == Berat(n))//cek obat sudah diambil atau belum
          if(button[1] == 0)//cek obat sudah diambil atau belum
          {  
            tiga:
            if(hour()==6 || hour()==12 || hour()==18)
            {
              if(minute()==1)//ketika jam 6 lebih 2 detik
                {
                if(millis()>time_1+interval_message)
                  {
                    time_1=millis();
                    //nyalakan Buzzer
                    Serial.println("Nyalakan Buzzer");
                    //digitalWrite(buzzer, HIGH);delay(10000); //nyalakan Buzzer 10 detik
                    //digitalWrite(buzzer, LOW); //Matikan Buzzer 10 detik

                    //fungsi gerakkan stepper
                    Serial.print("putar Stepper ke kotak ");Serial.println(i);
                    //stepper.setSpeed(4); // gerakkan Stepper dengan kecepatan 4 rpm
                    //stepper.step(255); // buka kotak (Lakukan 255 langkah)--sesuai dengan satu revolusi dalam satu menit
                  }//goto tiga;
                }

              if(minute()==5)//menit ke 5
                { 
                if(millis()>time_1+interval_message)
                  {
                    time_1=millis();
                    //nyalakan Buzzer
                    Serial.println("Nyalakan Buzzer, peringatan 5 menit");
                    //digitalWrite(buzzer, HIGH);delay(10000); //nyalakan Buzzer 10 detik
                    //digitalWrite(buzzer, LOW); //Matikan Buzzer 10 detik
                  } //goto tiga;
                }        

              if(minute()==59)//menit ke 59
                {
                if(millis()>time_1+interval_message)
                  {
                    time_1=millis();
                    //nyalakan Buzzer
                    Serial.println("Nyalakan Buzzer, peringatan 59 menit");
                    //digitalWrite(buzzer, HIGH);delay(10000); //nyalakan Buzzer 10 detik
                    //digitalWrite(buzzer, LOW); //Matikan Buzzer 10 detik

                    //kirim email
                    Serial.println("Kirim email notifikasi belum minum obat");
                  }//goto tiga;
                }
                else
                { 
                if(millis()>time_1+interval_message)
                  {
                    time_1=millis();
                    //Kotak stay membuka di kotak 1
                    Serial.print("sekarang jam :");Serial.print(hour());Serial.print(" ");
                    Serial.println("Jam Sesuai, kotak membuka menunggu notif berikutnya, dan obat belum diminum");
              
                  }//goto tiga;
                }
            }
            else{
                 if(millis()>time_1+interval_message)
                 {
                    time_1=millis();
                    //Kotak_Close( kotak obat menutup ke awal(home)
                    Serial.println("kotak close(home) bukan waktu minum obat dan tidak ada alarm apapun");
            
                 }//goto cek_box3;
                }
         }
         else{
              if(millis()>time_1+interval_message)
                {
                  time_1=millis();
                  //Cek nilai kotak berikutnya
                  //kirim email
                  Serial.print("obat kotak ke ");Serial.print(i);Serial.print(" sudah diminum ");
                  Serial.print("Cek nilai kotak berikutnya yang ke ");Serial.println(i+1);
                  ////goto sini;
                }
              }
              
      button[1]=0;
      Serial.println(button[1]);  
      break;  
  
  case 4:
          cek_box4:
          //minum 1 kali
          Serial.println("Minum obat 2 kali");
     
          // while(Berat(n+1) == Berat(n))//cek obat sudah diambil atau belum
          if(button[1] == 0)//cek obat sudah diambil atau belum
          {  
            empat:
            if(hour()==6 || hour()==12 || hour()==18)
            {
              if(minute()==1)//ketika jam 6 lebih 2 detik
                {
                if(millis()>time_1+interval_message)
                  {
                    time_1=millis();
                    //nyalakan Buzzer
                    Serial.println("Nyalakan Buzzer");
                    //digitalWrite(buzzer, HIGH);delay(10000); //nyalakan Buzzer 10 detik
                    //digitalWrite(buzzer, LOW); //Matikan Buzzer 10 detik

                    //fungsi gerakkan stepper
                    Serial.print("putar Stepper ke kotak ");Serial.println(i);
                    //stepper.setSpeed(4); // gerakkan Stepper dengan kecepatan 4 rpm
                    //stepper.step(255); // buka kotak (Lakukan 255 langkah)--sesuai dengan satu revolusi dalam satu menit
                  }//goto empat;
                }

              if(minute()==5)//menit ke 5
                { 
                if(millis()>time_1+interval_message)
                  {
                    time_1=millis();
                    //nyalakan Buzzer
                    Serial.println("Nyalakan Buzzer, peringatan 5 menit");
                    //digitalWrite(buzzer, HIGH);delay(10000); //nyalakan Buzzer 10 detik
                    //digitalWrite(buzzer, LOW); //Matikan Buzzer 10 detik
                  } //goto empat;
                }        

              if(minute()==59)//menit ke 59
                {
                if(millis()>time_1+interval_message)
                  {
                    time_1=millis();
                    //nyalakan Buzzer
                    Serial.println("Nyalakan Buzzer, peringatan 59 menit");
                    //digitalWrite(buzzer, HIGH);delay(10000); //nyalakan Buzzer 10 detik
                    //digitalWrite(buzzer, LOW); //Matikan Buzzer 10 detik

                    //kirim email
                    Serial.println("Kirim email notifikasi belum minum obat");
                  }//goto empat;
                }
                else
                { 
                if(millis()>time_1+interval_message)
                  {
                    time_1=millis();
                    //Kotak stay membuka di kotak 1
                    Serial.print("sekarang jam :");Serial.print(hour());Serial.print(" ");
                    Serial.println("Jam Sesuai, kotak membuka menunggu notif berikutnya, dan obat belum diminum");
              
                  }//goto empat;
                }
            }
            else{
                 if(millis()>time_1+interval_message)
                 {
                    time_1=millis();
                    //Kotak_Close( kotak obat menutup ke awal(home)
                    Serial.println("kotak close(home) bukan waktu minum obat dan tidak ada alarm apapun");
            
                 }//goto cek_box4;
                }
         }
         else{
              if(millis()>time_1+interval_message)
                {
                  time_1=millis();
                  //Cek nilai kotak berikutnya
                  //kirim email
                  Serial.print("obat kotak ke ");Serial.print(i);Serial.print(" sudah diminum ");
                  Serial.print("Cek nilai kotak berikutnya yang ke ");Serial.println(i+1);
                  ////goto sini;
                }
              }
              
      button[1]=0;
      Serial.println(button[1]);  
      break;
  
  default:
      if(millis()>time_1+interval_message)
      {
        time_1=millis();
        printf("Maaf, format nilai tidak sesuai \n");
        //////goto sini;
      }
      break;
   }
  
  }

}


void setup()
{
  // Debug console
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);

  // Clear the Pil_6 content
  Pil_1.clear();
  Pil_2.clear();
  Pil_3.clear();
  Pil_4.clear();
  Pil_5.clear();
  Pil_6.clear();
  

  // This will print Blynk Software version to the Terminal Widget when
  // your hardware gets connected to Blynk Server
  terminal.println(F("Blynk v" BLYNK_VERSION ": Device started"));
  terminal.println(F("-------------"));
  terminal.println(F("Type time one until 5 and get a reply, or type"));
  terminal.println(F("anything else and get it printed back."));
  terminal.flush();

  setSyncInterval(10 * 60); // Sync interval in seconds (10 minutes)

  // Display digital clock every 10 seconds
  timer.setInterval(1000L, CekOutput);
  
  // Display digital clock every 10 seconds
  timer.setInterval(1000L, clockDisplay);

  // Display digital clock every 10 seconds
  //timer.setInterval(1000L, Program);
  
}

void loop()
{
  Blynk.run();
  timer.run();
}

image
image

but when I want to use the input value (SaveArray []) into the program void function and run the program I experience failure by not being able to save the array value again, then I try to make a comment on

    //timer.setInterval(1000L, Program);

and finally the value of the user input was successfully saved in SaveArray [] and successfully displayed but when I deleted the comment on the code below

    timer.setInterval (1000L, Program); 

the program no longer manages to save for input value 1 or SaveArray [1] and surprisingly the input value 1 or SaveArray [1] is filled with the value SaveArray [6] like figure below even though the value in Blynk is correct. even though I want to run the program’s function to see whether the program is what I want or not. thanks you

image
image