I want the program to wait for an input before continuing.

Hello, below is the code that will be used for an automated pill dispenser. I'm using an Arduino Redboard and an LCD (16x2). When the code runs, it should ask the user to answer different questions such as "number of pills" and "'how often do you want pills?" The user will input this information using buttons that increase and decrease the selection. I also have a continue button and I want the program to wait until that button is pressed for moving on to the next question. For example, the program will ask the user "how many pills?". Once the user is satisfied, they will press the continue button. This will move on to the next question. Currently, when I run the code, the program will rapidly print all the questions rather than wait for the continue button.

#include <LiquidCrystal.h>
#include <Servo.h>
String words;
unsigned long time; //this is used for determining the amount of time since the arduino started
Servo A; // motor 1
Servo B; // motor 2
Servo C; // motor 3

int pills1=0;   // each motor will have its own set of variables.
int timebetweenpills1 = 0;
int pills2=0;
int timebetweenpills2 = 0;
int pills3=0;
int timebetweenpills3 = 0;
int selection =0; // This variable is changed by pressing buttons.
int upbutton =6;
int downbutton =7;
int contbutton =8;
int rotations1 = 0;
int a; //variable that controls number of rotations motor does to dispense x number of pills
int b;
int c;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
  time = millis() ;  // sets time since program started = time
  pinMode(6, INPUT);
  pinMode(7, INPUT);  
  pinMode(8, INPUT); //this button advances the user to the next questions during setup
  pinMode(9, OUTPUT); 
  A.attach(9);  // attaches first servo motor to pin 8
    pinMode(10, OUTPUT);
    B.attach(10);
      pinMode(13, OUTPUT);
      C.attach(13);
    Serial.begin(9600);
    
    lcd.begin(16,2);
    lcd.setCursor(0,1); //sets up LCD

 
 lcd.clear();
 delay(10);
 int selection = 0;
 while (contbutton == LOW); {  // runs user selection loop until continue button is pressed
  lcd.print("Pills #1"); // Asks user how many pills they want at a time
  if (upbutton == HIGH); { //upbutton increases selection
selection = selection + 1 ; 
    delay(1000); 
  }
  if (downbutton == HIGH); {  //downbutton decreases selection
selection = selection - 1 ;
    delay(500); }
    pills1 = selection;
    lcd.print("Pills =");
    lcd.setCursor(1,1);
    lcd.print(selection);
    Serial.println(selection);
  }

   lcd.clear();
 lcd.print("How Often 1?"); // asks user how many hours between each set of pills
  selection = 0;
 while (contbutton == LOW); {
  if (upbutton == HIGH); {
selection = selection + 1 ;
    delay(500); 
  }
  if (downbutton == HIGH); {
selection = selection - 1 ;
    delay(500); }
    timebetweenpills1 = selection * 3600000; // 3600000 milliseconds is an hour. If user selects 2 hours, timebetweenpills will = 7200000 milliseconds
    lcd.print("Hours =");
    lcd.print(selection);
    Serial.println(selection);
  }

  lcd.clear();
 lcd.print("Pills #2"); // Asks for amount of pills dispensed at a time for the 2nd supply
 selection = 0;
 while (contbutton == LOW); {
  if (upbutton == HIGH); {
selection = selection + 1 ;
    delay(500); 
  }
  if (downbutton == HIGH); {
selection = selection - 1 ;
    delay(500); }
    pills2 = selection;
    lcd.print("Pills =");
    lcd.print(selection);
    Serial.println(selection);
  }

   lcd.clear();
 lcd.print("How Often 2?");
  selection = 0;
 while (contbutton == LOW); {
  if (upbutton == HIGH); {
selection = selection + 1 ;
    delay(500); 
  }
  if (downbutton == HIGH); {
selection = selection - 1 ;
    delay(500); }
    timebetweenpills2 = selection * 3600000;
    lcd.print("Hours =");
    lcd.print(selection);
    Serial.println(selection);
  }

 lcd.clear();
 lcd.print("Pills #3");
 selection = 0;
 while (contbutton == LOW); {
  if (upbutton == HIGH); {
selection = selection + 1 ;
    delay(500); 
  }
  if (downbutton == HIGH); {
selection = selection - 1 ;
    delay(500); }
    pills3 = selection;
    lcd.print("Pills =");
    lcd.print(selection);
    Serial.println(selection);
  }

 lcd.clear();
 lcd.print("How Often 3?");
  selection = 0;
 while (contbutton == LOW); {
  if (upbutton == HIGH); {
selection = selection + 1 ;
    delay(500); 
  }
  if (downbutton == HIGH); {
        lcd.setCursor(1,1);
     lcd.print("Hours =");
    lcd.print(selection);
    Serial.println(selection);
selection = selection - 1 ;
    wait(500); }
    timebetweenpills3 = selection * 3600000;

   
  }
  

 }
 






void loop() {
 
Serial.println(time);
a = 0;  
if (timebetweenpills1 = time && a <= pills1) {    // when the timebetween pills is equal to arduino run time, the motor will activate.
A.write(90);                                       // the motor will quit running when the amount of pills dispensed is equal to pills1
delay(10);
A.write(0);
a = a + 1 ;                                         // Each time a pill is dispensed, a increases by 1 until it is equal to pills1. Once it is equal, the motor stops
}
b= 0 ;
if (timebetweenpills2 = time && b <= pills2) {     // same code as above, but for storage #2
B.write(90);
delay(10);
B.write(0);
b = b + 1 ;
}
c = 0 ;
if (timebetweenpills3 = time && c <= pills3) {
C.write(90);
delay(10);
C.write(0);
c = c + 1 ;
}

  


}

Hi, it might be useful to look at this: How to make the loop wait for user input and then continue? - Programming Questions - Arduino Forum
It seems to be related to what you want to do - including the button functionality. I know it is slightly different than your project, but at least it is a starting point :slight_smile: