Skip to content

Commit 937357e

Browse files
committed
pioasm_neopixel: Adapt to various boards
On any board with a NEOPIXEL pin defined, use it. Otherwise, arbitrarily use D16 which is conveniently at a corner of the Pico board. Send several different pixel colors so that the user can see it working.
1 parent 235dc40 commit 937357e

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

examples/pioasm_neopixel.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import time
66
import rp2pio
77
import board
8+
import microcontroller
89
import adafruit_pioasm
910

1011
# NeoPixels are 800khz bit streams. Zeroes are 1/3 duty cycle (~416ns) and ones
@@ -25,21 +26,31 @@
2526

2627
assembled = adafruit_pioasm.assemble(program)
2728

29+
# If the board has a designated neopixel, then use it. Otherwise use
30+
# GPIO16 as an arbitrary choice.
31+
if hasattr(board, "NEOPIXEL"):
32+
NEOPIXEL = board.NEOPIXEL
33+
else:
34+
NEOPIXEL = microcontroller.pin.GPIO16
35+
2836
sm = rp2pio.StateMachine(
2937
assembled,
3038
frequency=800000 * 6, # 800khz * 6 clocks per bit
31-
init=adafruit_pioasm.assemble("set pindirs 1"),
32-
first_set_pin=board.D12,
33-
first_sideset_pin=board.D12,
39+
first_set_pin=NEOPIXEL,
40+
first_sideset_pin=NEOPIXEL,
3441
auto_pull=True,
3542
out_shift_right=False,
3643
pull_threshold=8,
3744
)
3845
print("real frequency", sm.frequency)
3946

40-
for i in range(100):
47+
for i in range(30):
4148
sm.write(b"\x0a\x00\x00")
4249
time.sleep(0.1)
50+
sm.write(b"\x00\x0a\x00")
51+
time.sleep(0.1)
52+
sm.write(b"\x00\x00\x0a")
53+
time.sleep(0.1)
4354
print("writes done")
4455

4556
time.sleep(2)

0 commit comments

Comments
 (0)