Problem in the countdown timer (millis)

Hi! I want to do a countdown timer. With the usually led blink in milliseconds () everything is easy, but when trying to make a countdown timer, problems arise. I send the number 1, then the LED lights up and the timer starts, which should turn off the led after 5 seconds, but the LED remains on and does not respond to the timer. What is my error?

byte incomingByte;
bool led = false;
unsigned long timer;

void setup() {
  pinMode(6, OUTPUT);
  Serial.begin(9600);
}

void led(int state){
  if(state == 10) {
    if(led == false) {
    digitalWrite(6, HIGH);
    timer = millis();
    led = true;
    }
    if(millis() - timer >= 5000 && led == true) {
      digitalWrite(6, LOW);
      state = 0;
      led = false;
    }
  }
}

void loop() {
      if (Serial.available() > 0) {
    incomingByte = Serial.read();
    if(incomingByte == '1') {
      led(10);
    }
  }
}

but the LED remains on and does not respond to the timer. What is my error?

Your function is called ONCE. The condition necessary to turn the LED off is not true when the function is called.

Thanks for the help! The timer started working when I inserted it into the loop() function. Is there a way to make this timer work inside the led() function?

byte incomingByte;
bool leds = false;
unsigned long timer;

void led(int state){
  if(state == 10) {
    if(leds == false) {
    digitalWrite(6, HIGH);
    timer = millis();
    leds = true;
    }
  }
}

void setup() {
  pinMode(6, OUTPUT);
  Serial.begin(9600);
}


void loop() {
      if (Serial.available() > 0) {
    incomingByte = Serial.read();
    if(incomingByte == '1') {
      led(10);
    }
  }
  if(leds == true) {
      if(millis() - timer >= 5000) {
      digitalWrite(6, LOW);
      leds = false;
    }
  }
}

There are many examples about tiking by millis(), and no one uses fubctiins like this. An example is the first post in this forum