Skip to content

Commit b5b8e35

Browse files
committed
add blink example
1 parent d727e55 commit b5b8e35

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

examples/pico-examples/blink.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# SPDX-FileCopyrightText: 2021 Jeff Epler, written for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
#
5+
# Adapted from the example https://github.com/raspberrypi/pico-examples/tree/master/pio/pio_blink
6+
7+
import adafruit_pioasm
8+
import board
9+
import array
10+
import rp2pio
11+
import time
12+
13+
blink = adafruit_pioasm.assemble(
14+
"""
15+
.program blink
16+
pull block ; These two instructions take the blink duration
17+
out y, 32 ; and store it in y
18+
forever:
19+
mov x, y
20+
set pins, 1 ; Turn LED on
21+
lp1:
22+
jmp x-- lp1 ; Delay for (x + 1) cycles, x is a 32 bit number
23+
mov x, y
24+
set pins, 0 ; Turn LED off
25+
lp2:
26+
jmp x-- lp2 ; Delay for the same number of cycles again
27+
jmp forever ; Blink forever!
28+
"""
29+
)
30+
31+
32+
while True:
33+
for freq in [5, 8, 30]:
34+
with rp2pio.StateMachine(
35+
blink,
36+
frequency=125_000_000,
37+
first_set_pin=board.LED,
38+
wait_for_txstall=False,
39+
) as sm:
40+
data = array.array("I", [sm.frequency // freq])
41+
sm.write(data)
42+
time.sleep(3)
43+
time.sleep(0.5)

0 commit comments

Comments
 (0)