import machine
import time                     

led=machine.Pin(2, machine.Pin.OUT)      
start=time.ticks_ms()           

while True:
    
    delta = time.ticks_diff(time.ticks_ms(), start) #compute the time difference between start and current time
    
    if delta>=500:              #if the difference is greater or equal to 500 milliseconds
        if led.value()==0:
            led(1)
            start=time.ticks_ms()  
        else:
            led(0)
            start=time.ticks_ms()