user87196: I am currently building an automatic Pet Feeder using Arduino Uno.
What I wanted to do is, after I input the necessary data (the days. hours, and minutes), I want to stop the loop of days until it ends or 'reset' the input data by pressing 'D'. I don't want to reset the whole arduino since it will affect the servo and will rotate 360°.
The only solution that I have now is to have a button directly connected to the reset pin of the arduino, however, this will affect my servo; that is what I am avoiding

         if (keypressed == 'B' && stop == true)
         {

                      if (keypressed == 'D') {
                        stop = false;
                        exit();
                      }



          
          lcd.clear();
          lcd.print("  Days setup  ");
          delay(1000);
          lcd.clear();


          lcd.print("Set no. of Day"); //B_days
          char   keypressed18 = myKeypad.waitForKey();
                if (keypressed18 != NO_KEY && keypressed18 !='*' && keypressed18 !='#' && keypressed18 !='A' && keypressed18 !='B' && keypressed18 !='C' && keypressed18 !='D' )
                  {
                    c1 = keypressed18;
                   lcd.setCursor(0, 1);
                   lcd.print(c1);
                   }
                 i1=48-c1;
                 B_days=abs(i1);
                 Serial.print(B_days);
                 delay(500);
                 lcd.clear();



                 lcd.print("  MEAL 1  "); 
                 delay(1000);
                 lcd.clear();                     
                 lcd.print("Set FEED hour");
           
                char keypressed19 = myKeypad.waitForKey();  // here all programs are stopped until you enter the four digits then it gets compared to the code above
                if (keypressed19 != NO_KEY && keypressed19 !='*' && keypressed19 !='#' && keypressed19 !='A' && keypressed19 !='B' && keypressed19 !='C' && keypressed19 !='D' )
                  {
                   c2 = keypressed19;
                   lcd.setCursor(0, 1);
                   lcd.print(c2);
                   }
                char   keypressed20 = myKeypad.waitForKey();
                if (keypressed20 != NO_KEY && keypressed20 !='*' && keypressed20 !='#' && keypressed20 !='A' && keypressed20 !='B' && keypressed20 !='C' && keypressed20 !='D' )
                  {
                    c3 = keypressed20;
                   lcd.setCursor(1, 1);
                   lcd.print(c3);
                   }


                 i1=(c2-48)*10;
                 i2=c3-48;
                 B_hour1=i1+i2;
                delay(500);
                lcd.clear();
                
                
                lcd.print("Set FEED minutes");
                  char keypressed21 = myKeypad.waitForKey();  // here all programs are stopped until you enter the four digits then it gets compared to the code above
                if (keypressed21 != NO_KEY && keypressed21 !='*' && keypressed21 !='#' && keypressed21 !='A' && keypressed21 !='B' && keypressed21 !='C' && keypressed21 !='D' )
                  {
                   c1 = keypressed21;
                   lcd.setCursor(0, 1);
                   lcd.print(c1);
                   }
                char   keypressed22 = myKeypad.waitForKey();
                if (keypressed22 != NO_KEY && keypressed22 !='*' && keypressed22 !='#' && keypressed22 !='A' && keypressed22 !='B' && keypressed22 !='C' && keypressed22 !='D' )
                  {
                    c2 = keypressed22;
                   lcd.setCursor(1, 1);
                   lcd.print(c2);
                   }


                 i1=(c1-48)*10;
                 i2=c2-48;
                 B_minute1=i1+i2;
                 Serial.print(B_minute1);
                 delay(500);
                 lcd.clear();
                 

                 lcd.print("  MEAL 2  ");
                 delay(1000);
                 lcd.clear(); 
                 lcd.print("Set FEED hour");
           
                char keypressed23 = myKeypad.waitForKey();  // here all programs are stopped until you enter the four digits then it gets compared to the code above
                if (keypressed23 != NO_KEY && keypressed23 !='*' && keypressed23 !='#' && keypressed23 !='A' && keypressed23 !='B' && keypressed23 !='C' && keypressed23 !='D' )
                  {
                   c2 = keypressed23;
                   lcd.setCursor(0, 1);
                   lcd.print(c2);
                   }
                char   keypressed24 = myKeypad.waitForKey();
                if (keypressed24 != NO_KEY && keypressed24 !='*' && keypressed24 !='#' && keypressed24 !='A' && keypressed24 !='B' && keypressed24 !='C' && keypressed24 !='D' )
                  {
                    c3 = keypressed24;
                   lcd.setCursor(1, 1);
                   lcd.print(c3);
                   }


                 i1=(c2-48)*10;
                 i2=c3-48;
                 B_hour2=i1+i2;
                delay(500);
                lcd.clear();
                

                lcd.print("Set FEED minutes");
                  char keypressed25 = myKeypad.waitForKey();  // here all programs are stopped until you enter the four digits then it gets compared to the code above
                if (keypressed25 != NO_KEY && keypressed25 !='*' && keypressed25 !='#' && keypressed25 !='A' && keypressed25 !='B' && keypressed25 !='C' && keypressed25 !='D' )
                  {
                   c1 = keypressed25;
                   lcd.setCursor(0, 1);
                   lcd.print(c1);
                   }
                char   keypressed26 = myKeypad.waitForKey();
                if (keypressed26 != NO_KEY && keypressed26 !='*' && keypressed26 !='#' && keypressed26 !='A' && keypressed26 !='B' && keypressed26 !='C' && keypressed26 !='D' )
                  {
                    c2 = keypressed26;
                   lcd.setCursor(1, 1);
                   lcd.print(c2);
                   }


                 i1=(c1-48)*10;
                 i2=c2-48;
                 B_minute2=i1+i2;
                 Serial.print(B_minute2);
                 delay(500);
                 lcd.clear();


                 
                 AlarmIsActive=2;
                 keypressed=NO_KEY;
      
         }


user40318: This is not a direct answer.
Your code is unnecessarily repetitive and complex.
Use a function to execute repeated code.
Here is an example of how you could do the numeric entry in a function.
The code is not tested.

int getNumber(String msg) {

   int data = 0;
   bool numNotPressed = true;             // a flag variable

   lcd.clear();                     
   lcd.print(msg);

   lcd.setCursor(0, 1);                   // set cursor to first position in second row

   while true {

      char key = myKeypad.waitForKey();

      if (  key != NO_KEY
         && key != '*'
         && key != '#'
         && key != 'A'
         && key != 'B'
         && key != 'C'
         && key != 'D'
      ) {                                 // number key was pressed
         lcd.print(key);                  // the cursor automatically advances
         d10 = data * 10;
         data = d10 + (key - 48);         // assemble multi-digit input
         numNotPressed = false;           // numeric key was pressed
      }
      
      else {
         if (numNotPressed) data = -1;    // -1 indicates that numeric key was not pressed
         return data;                     // return value to the calling code
      }
   }
}

// usage

    lcd.clear();
    lcd.print("  MEAL 2  ");
    delay(1000);

    num = getNumber("Set FEED hour");
    if (num > -1) {
       B_hour = num;                       // update B_hour if a numeric value was entered
    }


87196: <p>I am currently building an automatic Pet Feeder using Arduino Uno.</p>
<p>What I wanted to do is, after I input the necessary data (the days. hours, and minutes), I want to stop the loop of days until it ends or 'reset' the input data by pressing 'D'. I don't want to reset the whole arduino since it will affect the servo and will rotate 360°.</p>
<p>The only solution that I have now is to have a button directly connected to the reset pin of the arduino, however, this will affect my servo; that is what I am avoiding</p>
<hr />
<pre><code>         if (keypressed == 'B' &amp;&amp; stop == true)
         {

                      if (keypressed == 'D') {
                        stop = false;
                        exit();
                      }



          
          lcd.clear();
          lcd.print(&quot;  Days setup  &quot;);
          delay(1000);
          lcd.clear();


          lcd.print(&quot;Set no. of Day&quot;); //B_days
          char   keypressed18 = myKeypad.waitForKey();
                if (keypressed18 != NO_KEY &amp;&amp; keypressed18 !='*' &amp;&amp; keypressed18 !='#' &amp;&amp; keypressed18 !='A' &amp;&amp; keypressed18 !='B' &amp;&amp; keypressed18 !='C' &amp;&amp; keypressed18 !='D' )
                  {
                    c1 = keypressed18;
                   lcd.setCursor(0, 1);
                   lcd.print(c1);
                   }
                 i1=48-c1;
                 B_days=abs(i1);
                 Serial.print(B_days);
                 delay(500);
                 lcd.clear();



                 lcd.print(&quot;  MEAL 1  &quot;); 
                 delay(1000);
                 lcd.clear();                     
                 lcd.print(&quot;Set FEED hour&quot;);
           
                char keypressed19 = myKeypad.waitForKey();  // here all programs are stopped until you enter the four digits then it gets compared to the code above
                if (keypressed19 != NO_KEY &amp;&amp; keypressed19 !='*' &amp;&amp; keypressed19 !='#' &amp;&amp; keypressed19 !='A' &amp;&amp; keypressed19 !='B' &amp;&amp; keypressed19 !='C' &amp;&amp; keypressed19 !='D' )
                  {
                   c2 = keypressed19;
                   lcd.setCursor(0, 1);
                   lcd.print(c2);
                   }
                char   keypressed20 = myKeypad.waitForKey();
                if (keypressed20 != NO_KEY &amp;&amp; keypressed20 !='*' &amp;&amp; keypressed20 !='#' &amp;&amp; keypressed20 !='A' &amp;&amp; keypressed20 !='B' &amp;&amp; keypressed20 !='C' &amp;&amp; keypressed20 !='D' )
                  {
                    c3 = keypressed20;
                   lcd.setCursor(1, 1);
                   lcd.print(c3);
                   }


                 i1=(c2-48)*10;
                 i2=c3-48;
                 B_hour1=i1+i2;
                delay(500);
                lcd.clear();
                
                
                lcd.print(&quot;Set FEED minutes&quot;);
                  char keypressed21 = myKeypad.waitForKey();  // here all programs are stopped until you enter the four digits then it gets compared to the code above
                if (keypressed21 != NO_KEY &amp;&amp; keypressed21 !='*' &amp;&amp; keypressed21 !='#' &amp;&amp; keypressed21 !='A' &amp;&amp; keypressed21 !='B' &amp;&amp; keypressed21 !='C' &amp;&amp; keypressed21 !='D' )
                  {
                   c1 = keypressed21;
                   lcd.setCursor(0, 1);
                   lcd.print(c1);
                   }
                char   keypressed22 = myKeypad.waitForKey();
                if (keypressed22 != NO_KEY &amp;&amp; keypressed22 !='*' &amp;&amp; keypressed22 !='#' &amp;&amp; keypressed22 !='A' &amp;&amp; keypressed22 !='B' &amp;&amp; keypressed22 !='C' &amp;&amp; keypressed22 !='D' )
                  {
                    c2 = keypressed22;
                   lcd.setCursor(1, 1);
                   lcd.print(c2);
                   }


                 i1=(c1-48)*10;
                 i2=c2-48;
                 B_minute1=i1+i2;
                 Serial.print(B_minute1);
                 delay(500);
                 lcd.clear();
                 

                 lcd.print(&quot;  MEAL 2  &quot;);
                 delay(1000);
                 lcd.clear(); 
                 lcd.print(&quot;Set FEED hour&quot;);
           
                char keypressed23 = myKeypad.waitForKey();  // here all programs are stopped until you enter the four digits then it gets compared to the code above
                if (keypressed23 != NO_KEY &amp;&amp; keypressed23 !='*' &amp;&amp; keypressed23 !='#' &amp;&amp; keypressed23 !='A' &amp;&amp; keypressed23 !='B' &amp;&amp; keypressed23 !='C' &amp;&amp; keypressed23 !='D' )
                  {
                   c2 = keypressed23;
                   lcd.setCursor(0, 1);
                   lcd.print(c2);
                   }
                char   keypressed24 = myKeypad.waitForKey();
                if (keypressed24 != NO_KEY &amp;&amp; keypressed24 !='*' &amp;&amp; keypressed24 !='#' &amp;&amp; keypressed24 !='A' &amp;&amp; keypressed24 !='B' &amp;&amp; keypressed24 !='C' &amp;&amp; keypressed24 !='D' )
                  {
                    c3 = keypressed24;
                   lcd.setCursor(1, 1);
                   lcd.print(c3);
                   }


                 i1=(c2-48)*10;
                 i2=c3-48;
                 B_hour2=i1+i2;
                delay(500);
                lcd.clear();
                

                lcd.print(&quot;Set FEED minutes&quot;);
                  char keypressed25 = myKeypad.waitForKey();  // here all programs are stopped until you enter the four digits then it gets compared to the code above
                if (keypressed25 != NO_KEY &amp;&amp; keypressed25 !='*' &amp;&amp; keypressed25 !='#' &amp;&amp; keypressed25 !='A' &amp;&amp; keypressed25 !='B' &amp;&amp; keypressed25 !='C' &amp;&amp; keypressed25 !='D' )
                  {
                   c1 = keypressed25;
                   lcd.setCursor(0, 1);
                   lcd.print(c1);
                   }
                char   keypressed26 = myKeypad.waitForKey();
                if (keypressed26 != NO_KEY &amp;&amp; keypressed26 !='*' &amp;&amp; keypressed26 !='#' &amp;&amp; keypressed26 !='A' &amp;&amp; keypressed26 !='B' &amp;&amp; keypressed26 !='C' &amp;&amp; keypressed26 !='D' )
                  {
                    c2 = keypressed26;
                   lcd.setCursor(1, 1);
                   lcd.print(c2);
                   }


                 i1=(c1-48)*10;
                 i2=c2-48;
                 B_minute2=i1+i2;
                 Serial.print(B_minute2);
                 delay(500);
                 lcd.clear();


                 
                 AlarmIsActive=2;
                 keypressed=NO_KEY;
      
         }
</code></pre>
 40318: <p>This is not a direct answer.</p>
<p>Your code is unnecessarily repetitive and complex.</p>
<p>Use a function to execute repeated code.</p>
<p>Here is an example of how you could do the numeric entry in a function.</p>
<p>The code is not tested.</p>
<pre class="lang-cpp prettyprint-override"><code>
int getNumber(String msg) {

   int data = 0;
   bool numNotPressed = true;             // a flag variable

   lcd.clear();                     
   lcd.print(msg);

   lcd.setCursor(0, 1);                   // set cursor to first position in second row

   while true {

      char key = myKeypad.waitForKey();

      if (  key != NO_KEY
         &amp;&amp; key != '*'
         &amp;&amp; key != '#'
         &amp;&amp; key != 'A'
         &amp;&amp; key != 'B'
         &amp;&amp; key != 'C'
         &amp;&amp; key != 'D'
      ) {                                 // number key was pressed
         lcd.print(key);                  // the cursor automatically advances
         d10 = data * 10;
         data = d10 + (key - 48);         // assemble multi-digit input
         numNotPressed = false;           // numeric key was pressed
      }
      
      else {
         if (numNotPressed) data = -1;    // -1 indicates that numeric key was not pressed
         return data;                     // return value to the calling code
      }
   }
}

// usage

    lcd.clear();
    lcd.print(&quot;  MEAL 2  &quot;);
    delay(1000);

    num = getNumber(&quot;Set FEED hour&quot;);
    if (num &gt; -1) {
       B_hour = num;                       // update B_hour if a numeric value was entered
    }
</code></pre>
