# Simple tutorial demonstrating PIO on the Pi Pico

import rp2
from machine import Pin
import time

@rp2.asm_pio(out_init=(rp2.PIO.OUT_LOW,rp2.PIO.OUT_LOW,rp2.PIO.OUT_LOW,rp2.PIO.OUT_LOW ))
#we initialize 4 pins starting with pin 10 (base pin )
def out():
    pull(block) # read stuff put here by "sm.put"
    out(pins , 4) # and send it to the pins ...
#creating a State Machine , #0 , running function "out" at 2kHz , first pin is pin 10 , LSB first out
sm = rp2.StateMachine(0, out, freq=2000, out_base=Pin(10),out_shiftdir=rp2.PIO.SHIFT_RIGHT)

# starting and "feeding" the state machine ...
sm.active(1)
for i in range(16): 
    print(f" i is now :{i}")
    sm.put(i)
    time.sleep(1)

print("resetting counter in 3 seconds ...")
time.sleep(3)
# reset counter
sm.put(0)
