from machine import Pin
import rp2
import time
# Define the PIO program
@rp2.asm_pio(
autopull=True, # Enable autopull to automatically pull data from the TX FIFO
pull_thresh=32,
out_init=(rp2.PIO.OUT_LOW,) * 4,
out_shiftdir=rp2.PIO.SHIFT_LEFT,
# Set the threshold for autopull to 32 bits
)
def blink_led():
pull(ifempty)
out(pins, 4) # Output 32 bits of data from the shift register to the pin
set(y, 31) # Set delay counter to 31
label("delay")
nop() [31] # Small delay loop
jmp(y_dec, "delay") # Decrement counter and loop until zero
# Create a Pin object for the LED
led_pin = Pin(0, Pin.OUT) # LED connected to GPIO 25
# Initialize the State Machine with the blink_led program
sm = rp2.StateMachine(0, blink_led, freq=20000, out_base=led_pin)
sm.active(1)
# Main loop
while True:
# Load data into the TX FIFO to control the LED
sm.put(0x1) # Load 32 bits of data to turn the LED on
time.sleep(1) # Wait for 1 second
sm.put(0x2) # Load 32 bits of data to turn the LED off
time.sleep(1) # Wait for 1 second