While loop won't start

This code is in a stand alone sketch that runs just fine. but when i migrate it to my main project, it never seems to enter the while loop. what gives? I get the “gate is raised” println but never get the “in while” print line.

thanks for the help. I think after this i’m pretty much done with this project to this extent/design.

unsigned long interval=5000; // the time we need to wait
unsigned long previousMillis=0; // millis() returns an unsigned long.
unsigned long startMillis = millis(); // grab current time

if(txt == "1121129999000000000000") {//"ppcc"

      Serial.println("passcode accepted");
      //raise gate
      raisegate();
      delay(5000);
      Serial.println("gate is raised");
      //lower gate
      while((unsigned long)(millis() - startMillis) <= interval){// check if "interval" time has passed (5000 milliseconds)
        Serial.println("in while");
        if(digitalRead(2) == LOW){
          lowergate();
        }else if(digitalRead(2) == HIGH){
          raisegate();
        }else{
        digitalWrite(3,HIGH);
      }
    }
  }

void lowergate(){
//  Serial.println("startmills is: " + startMillis)
  Serial.println("lowering the gate function");
  digitalWrite(3,HIGH);//change led state. these 3 lines simulate gate lifting code
//  ledState = !ledState;// "toggles" the state
  delay(100);//only to make led flash, wont be in final version
  digitalWrite(3,LOW);
  delay(100);
}
void raisegate(){
  Serial.println("raising gate fucntion");
  digitalWrite(3, LOW);
}

added this just before my code, fixed it. guess its a timing thing

      previousMillis=0;
      startMillis = millis();

ty

No idea. As a minimum, you should post the function that this code is part of (not a snippet). You should also post a simple sketch that uses that function and demonstrates the issue.

But OK, you seem to have solved it.

Probably caused by a stray 'elegant in the room'.