Turning an LED on when an error occurs, then turn it off after 2 seconds
When you turn on the led, record the time. 

After that, turn off the led if 


The led is on and
Sufficient time has passed.


edit: this is what I would do.

//detect if sufficient time has passed
//1. turn on the led on button high -&gt; low transition
//2. turn off the led after certain time (LED_DLY)
uint8_t led_ctrl(void) {
    static uint32_t led_timeoff=0;                              //time to turn the led off
    uint32_t time_now = millis();                               //take time now

    //if sufficient delay has passed, turn the led off
    if (isLED_ON() &amp;&amp; (time_now &gt;= led_timeoff)) {              //if led is already on
        LED_OFF();                                              //turn off the led
    }

    //if the button has experienced a the falling edge, turn on the led and set up the time to turn the led off
    if (btn_pressed()) {
        LED_ON();                                               //turn on the led
        led_timeoff = time_now + LED_DLY;                       //set up the time to turn off the led
    }

}


it is almost a literal implementation of what I wrote above.

here is the code in action, responding to button's falling edge with a 150ms delay turn off for the led: the button is on D12 and the led on D8.



fairly straight forward, isn't it?