while and millis

Hello,
I am having a problem getting my button to respond to the following code. I am trying to be able to give the user 1 minute to push the button and turn on an LED before the rest of my code runs. BUT... something is not working properly. Can anyone identify my problem?
Thank you,
Jason

const int buttonPin = 3;
const int ledPin =1;
unsigned long time;

void setup () {
    pinMode(buttonPin,INPUT);
    pinMode(ledPin,OUTPUT);
  }

void loop(){
      int buttonState;
      buttonState = digitalRead(buttonPin);
      time = millis();

      while(time < 60000){

       if (buttonState ==LOW)
         {
           digitalWrite(ledPin,HIGH);
         }
         else{
           digitalWrite(ledPin,LOW);
         }}}
      time = millis();

      while(time < 60000){

Once the while loop starts, it will never end, since time does not change inside the body of the statement.

Perhaps, you want while(millis() < 60000). But, then, after the Arduino has been running for 60 seconds, that won't ever be true again.

So, what you REALLY need to do is re-read the blink without delay example.

You need to read the pin within the while loop. Since you don't, buttonState never changes.

jasonandkids:

Although it won't solve your problem, note that:

 if (buttonState ==LOW)
         {
           digitalWrite(ledPin,HIGH);
         }
         else{
           digitalWrite(ledPin,LOW);
         }

condenses to:digitalWrite(ledPin,!digitalRead(buttonPin));