from machine import Pin
import time

# Define GPIO pins
green_led_pin = 21
blue_led_pin = 20
red_led_pin = 19
button_pin = 22

# Initialize LED and Button
green_led = Pin(green_led_pin, Pin.OUT)
blue_led = Pin(blue_led_pin, Pin.OUT)
red_led = Pin(red_led_pin, Pin.OUT)
button = Pin(button_pin, Pin.IN, Pin.PULL_UP)

def blink_led(led, nb_time:int=None, speed:float=0.5):
    i = 0
    if nb_time is None:
        while True:
            if button.value():
                led.off()
                return False
            led.on()
            time.sleep(speed)
            led.off()
            time.sleep(speed)
            print("blue led blinking")
    else:
        while i < nb_time:
            if button.value():
                led.off()
                return False
            green_led.on()
            time.sleep(speed)
            green_led.off()
            time.sleep(speed)
            i += 1
            print(f"green led blinked {i} times")
        return True
    

def turn_off_all():
    green_led.off()
    blue_led.off()
    red_led.off()

while True:
  # If Button pressed
  if not button.value():
    red_led.on()
    if blink_led(green_led, nb_time=20):
        blink_led(blue_led)
    # Else
  else:
    turn_off_all()
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT
pico:GP0
pico:GP1
pico:GND.1
pico:GP2
pico:GP3
pico:GP4
pico:GP5
pico:GND.2
pico:GP6
pico:GP7
pico:GP8
pico:GP9
pico:GND.3
pico:GP10
pico:GP11
pico:GP12
pico:GP13
pico:GND.4
pico:GP14
pico:GP15
pico:GP16
pico:GP17
pico:GND.5
pico:GP18
pico:GP19
pico:GP20
pico:GP21
pico:GND.6
pico:GP22
pico:RUN
pico:GP26
pico:GP27
pico:GND.7
pico:GP28
pico:ADC_VREF
pico:3V3
pico:3V3_EN
pico:GND.8
pico:VSYS
pico:VBUS
led1:A
led1:C
btn1:1.l
btn1:2.l
btn1:1.r
btn1:2.r
led2:A
led2:C
led3:A
led3:C