Raspberry Pi Pico: Onboard LED blinking Program

The following program will blink the onboard LED on the Raspberry Pi Pico.

from machine import Pin
from utime import sleep

pin = Pin("LED", Pin.OUT)

print("LED starts flashing...")
while True:
    try:
        pin.toggle()
        sleep(1) # sleep 1sec
    except KeyboardInterrupt:
        print("Finished.")
        break
pin.off()

This program works on Raspberry Pi Pico, Pico W, and Pico 2.

Ctrl + C will stop the program.