Updating...
from machine import Pin
import time
led = Pin(25, Pin.OUT)
while True:
led.toggle()
time.sleep(0.5)
or
from machine import Pin, Timer
led = Pin(25, Pin.OUT)
blink = lambda _: led.toggle()
Timer().init(mode=Timer.PERIODIC, period=500, callback=blink)
or
from machine import Pin
import uasyncio
async def blink(led):
while True:
led.toggle()
await uasyncio.sleep_ms(500)
uasyncio.run(blink(Pin(25, Pin.OUT)))
or
from machine import Pin
import rp2
@rp2.asm_pio(set_init=rp2.PIO.OUT_LOW)
def blink():
set(pins, 1)
set(x, 31) [6]
label('delay_high')
nop() [29]
jmp(x_dec, 'delay_high')
set(pins, 0)
set(x, 31) [6]
label('delay_low')
nop() [29]
jmp(x_dec, 'delay_low')
sm = rp2.StateMachine(0, blink, freq=2000, set_base=Pin(25))
sm.active(1)
The Pico has default frequency of 125 MHz but can be overclocked as high as 270 MHz (which uses higher CPU voltage and might be less stable):
from machine import freq
freq(270000000)
Remember to reset the frequency back to 125000000. (Note: firmware v1.18 seems fixed this problem.)
The NeoPixel driver is based on the official PIO example, repackaged into a class similar to CircuitPython's NeoPixel driver.
The DHT driver is based on Harry Fairhead & Mike James' DHT22 PIO code, repackaged into a class similar to MicroPython's dht module on ESP boards.
threads.py is a simple example of how to run two tasks simultaneously on both of RP2040's cores.
There's also two versions of Conway's Game of Life with OLED display, with or without utilizing dual cores.