Using Push Button as a Toggle

I cannot understand why this code works. If the pin is pulled up, then the reads in the loop would always be true, and as a result, the code should print some stuff to serial. It doesn't. It's as if the pullup is acting as a pulldown. Can someone please explain why this code is not constantly writing to serial?

const int button = 9; const int led = 13; int status = false;

void setup() { Serial.begin(9600); *pinMode(button, INPUT_PULLUP); * pinMode(led, OUTPUT); }

void loop() {

if(digitalRead(button) == true) // The button has to be true, the input pin is pulled up. { status = !status; digitalWrite(led, status); // turns on the led just fine Serial.print("Status is "); // and prints the status. Serial.println(status); }

while(digitalRead(button) == true); //at this point the input is still pulled up here, so why doesnt it //print the line below? { Serial.println("The button must be set to high"); delay(50); }

}

Does this look correct

Do you want the ; while(digitalRead(button) == true);

  while(digitalRead(button) == true);  //at this point the input is still pulled up here, so why doesnt it
                                                       //print the line below?

The body of that statement is the ; at the end. Until the condition is no longer true, the code after that statement is not reached/executed.

The curly braces around the code following the while statement are useless.

If there really is nothing to do, you should make that a LOT clearer:

  while(digitalRead(button) == true)
  { 
      ; // Do nothing while the switch is pressed
  }
// Now, the comment below makes no sense
 //at this point the input is still pulled up here, so why doesnt it
                                                       //print the line below?