While loop questions interfering with void loop?

Hi all im having a problem where the while loop is interfering with the void loop by I have to answer all of the questions first then the void loop will work once I have all of the questions answered, I am making a true or false game and I want to change the questions using the serial monitor instead of the code, keep in mind that im still writing the code so thats why theres not lots of code. Heres the code

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
const int redled=13;
const int blueled=12;
const int greenled=11;
const int falsebutton=10;
const int truebutton=9;
const int buzzer=8;
String message1, message2, message3, message4, message5, message6, message7, message8, message9, message10;
void setup() {
  Serial.begin(9600);
  lcd.init();
  lcd.backlight();
  pinMode(redled, OUTPUT);
  pinMode(greenled, OUTPUT);
  pinMode(blueled, OUTPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(falsebutton, INPUT_PULLUP);
  pinMode(truebutton, INPUT_PULLUP);
  digitalWrite(blueled, HIGH);
  messages();
}
void messages(){
   Serial.println("Enter Question 1");
  while(Serial.available()==0){}
  message1=Serial.readString();
  Serial.println("Enter Question 2");
  while(Serial.available()==0){}
  message2=Serial.readString();
  Serial.println("Enter Question 3");
  while(Serial.available()==0){}
  message3=Serial.readString();
  Serial.println("Enter Question 4");
  while(Serial.available()==0){}
  message4=Serial.readString();
  Serial.println("Enter Question 5");
  while(Serial.available()==0){}
  message5=Serial.readString();
  Serial.println("Enter Question 6");
  while(Serial.available()==0){}
  message6=Serial.readString();
  Serial.println("Enter Question 7");
  while(Serial.available()==0){}
  message7=Serial.readString();
  Serial.println("Enter Question 8");
  while(Serial.available()==0){}
  message8=Serial.readString();
  Serial.println("Enter Question 9");
  while(Serial.available()==0){}
  message9=Serial.readString();
  Serial.println("Enter Question 10");
  while(Serial.available()==0){}
  message10=Serial.readString();
  Serial.println("You have finished all of the questions");
}
void loop(){
  lcd.setCursor(0, 0); //Just testing to see the loop works here.
  lcd.print(message1);

Thanks for the help :slight_smile:

The function setup() has to complete before the loop() even starts. What you describe is perfectly normal.

So I basically need to call the messages() function in the void loop instead of the setup? But how would I make it loop the messages function once in the loop since it's going to keep looping.

Thanks, Brock

brockie14:
So I basically need to call the messages() function in the void loop instead of the setup?
Thanks, Brock

Yes.

But how would I make it loop the messages function once in the loop since it’s going to keep looping.

Study this and apply what you learn to your code.
Demonstration for several things at the same time

brockie14:
So I basically need to call the messages() function in the void loop instead of the setup? But how would I make it loop the messages function once in the loop since it's going to keep looping.

Thanks, Brock

I guess then you want messages() to be called at the beginning of a session and then on demand during the session, but not on every loop() iteration. How is the user going to input the information that he wants to trigger messages() to change the series of questions ? A key press or an entry in the serial console or what ?

There is no "void loop". There is a function called "loop" that doesn't return a value (and is thus
declared with return type "void"). Its important to get a handle on these concepts sooner rather than
later to reduce confusion.

Thanks guys :slight_smile: