Push Button Issues

So, im making a game, and i have a start button. the game is SUPPOSED to wait for you to press it, but then it skips it and continues. I havent finished the code, so im aware there is a loop in an awkward position, but IT BUGS THE HECK OUT OF ME! Ive tried 7 different designs of code. PLZ help.

Heres my code:

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
lcd.begin(16, 2);
lcd.clear();
pinMode(A0, OUTPUT);
pinMode(A2, OUTPUT);
pinMode(A4, OUTPUT);
pinMode(A1, INPUT);
pinMode(A3, INPUT);
pinMode(A5, INPUT);
}

void loop() {
lcd.setCursor(0, 0);
lcd.print(“H”);
delay(200);
lcd.print(“e”);
delay(200);
lcd.print(“l”);
delay(200);
lcd.print(“l”);
delay(200);
lcd.print(“o”);
delay(200);
lcd.print("!");
delay(3000);
lcd.clear();
lcd.print(“P”);
delay(200);
lcd.print(“r”);
delay(200);
lcd.print(“e”);
delay(200);
lcd.print(“s”);
delay(200);
lcd.print(“s”);
delay(200);
lcd.print(" ");
lcd.print(“Y”);
delay(200);
lcd.print(“e”);
delay(200);
lcd.print(“l”);
delay(200);
lcd.print(“l”);
delay(200);
lcd.print(“o”);
delay(200);
lcd.print(“w”);
while (digitalRead(A5) == LOW) {
}
lcd.clear();
}

So you want to wait for the button to be pressed? Go low?
THEN clear the screen?

  while (digitalRead(A5) == LOW) {
    //Do nothing
  }
  lcd.clear();

Or more simply (but slightly harder to understand for a beginner)...

  while (digitalRead(A5) == LOW);
  lcd.clear();

Note the ; is very important and the end of the while. It terminates the while when you don't have a set of braces { } to indicate what to repeat.

Crucially it is NOT the same as...

  while (digitalRead(A5) == LOW)
  lcd.clear();

Which, reading between the lines, I suspect you may have tried at some point.

Learn to use tags around your code when posting!

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

How have you got your button wired, do you have pullup or pulldown resistors?

Thanks.. Tom.. :slight_smile:

As Tom says:

TomGeorge:
Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

How have you got your button wired, do you have pullup or pulldown resistors?

Thanks.. Tom.. :slight_smile:

Configure your inputs like this:

pinMode(A5, INPUT_PULLUP);