A timer in a function

won't this turn the LED off (or on) immediately after it is turned on (or off)

try this

const byte PinLed =  LED_BUILTIN;

bool state;
unsigned long msec0;

void loop ()
{
    unsigned long msec = millis ();
    if (msec - msec0 >= 500)  {
        msec0 = msec;
        state = !state;
        digitalWrite (PinLed, state);
    }
}

void setup ()
{
    pinMode (PinLed, OUTPUT);
}