Project is really delayed Please Help!

Hi I am making a project that uses the serial monitor to put in a password that is right now "test" and then it will change a variable also if you enter "1" it will give you the status of the variable that is linked to the password. it all works but it is very delayed I was wondering what I was doing wrong

Thanks

int Password = 0;
void setup() {
  // Turn the Serial Protocol ON
  Serial.begin(9600);
  Serial.println("Initialized");
}

void loop() {
  if (Serial.readString() == "test") {
    Serial.println("Password Correct");
    Password = 1;
  }
  if (Serial.readString() == "1") {
    Serial.print("Password = ");
    Serial.println(Password);
    Serial.println("Ready");
  }
}

sketch_nov21c.ino (374 Bytes)

To make it respond more quickly, lookup Serial.setTimeout(). That may not be your only problem, though.

readString uses a timeout which makes it slow.

You should only read once from the serial port and store the result in a variable. Next analyse what is stored in the variable. That will save you one 'delay'.

I further suggest that you read Robin2's serial input basics thread (do a search). With the approaches described in that thread all 'delays' will disappear.

What have you got the Line Ending set to in the Serial monitor ?