from machine import Pin, Timer
red=Pin(0,Pin.OUT)
green=Pin(2,Pin.OUT)
yellow=Pin(6,Pin.OUT)
flag=0;
def cycle_leds(timer):
global flag
red.off()
green.off()
yellow.off()
if flag == 0:
red.on()
elif flag == 1:
green.on()
elif flag == 2:
yellow.on()
flag = (flag + 1) % 3
timer = Timer(period=1000, mode=Timer.PERIODIC, callback=cycle_leds)