Sources for the PIO Blog-Post

This commit is contained in:
Olli Graf
2024-08-22 09:43:22 +02:00
commit 15b89e2431
2 changed files with 49 additions and 0 deletions

29
blink-led-pio.py Normal file
View File

@@ -0,0 +1,29 @@
from machine import Pin
import rp2
from time import sleep
@rp2.asm_pio(set_init=rp2.PIO.OUT_LOW)
def blink():
wrap_target()
set(pins, 1) [31]
nop() [31]
nop() [31]
nop() [31]
set(pins, 0) [31]
nop() [31]
nop() [31]
nop() [31]
wrap()
led = machine.Pin(25, machine.Pin.OUT)
sm = rp2.StateMachine(0, blink, freq=2000, set_base=led)
# StateMachine aktivieren
sm.active(1)
# Für 3 Sekunden laufen lassen.
sleep(3)
# deaktivieren
sm.active(0)

20
blink-led.py Normal file
View File

@@ -0,0 +1,20 @@
from machine import Pin
from utime import sleep
led = machine.Pin(25, machine.Pin.OUT)
state = False
running = True
#Endlosschleife
led.off()
while True:
state = not state # state hin- und herschalten
sleep(1.0)
if state:
print('LED on')
led.on()
# running = False
else:
print('LED off')
led.off()