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
      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){
        }else if(digitalRead(2) == 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
void raisegate(){
  Serial.println("raising gate fucntion");
  digitalWrite(3, LOW);

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

      startMillis = millis();


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'.