Raspberry Pi Pico Python SDK
List of Files
A list of files with descriptions of their function;
neopixel_ring.py
The example code.
Pico MicroPython Examples:
1
# Example using PIO to drive a set of WS2812 LEDs.
2
3
import
4
from
5
import
6
7
# Configure the number of WS2812 LEDs.
8 NUM_LEDS =
9 PIN_NUM =
10 brightness =
11
12 @rp2.asm_pio(sideset_init=rp2.PIO.OUT_LOW, out_shiftdir=rp2.PIO.SHIFT_LEFT, autopull=True,
pull_thresh=24)
13
def
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Create the StateMachine with the ws2812 program, outputting on pin
28 sm = rp2.StateMachine(0, ws2812, freq=8_000_000, sideset_base=Pin(PIN_NUM))
29
30
# Start the StateMachine, it will wait for data on its FIFO.
31 sm.active(1)
32
33
# Display a pattern on the LEDs via an array of LED RGB values.
34 ar = array.array("I",
35
36
##########################################################################
37
def
38
39
40
41
42
43
44
45
46
47
def
48
49
50
def
51
52
Using PIO to drive a set of NeoPixel Ring (WS2812 LEDs)
https://github.com/raspberrypi/pico-micropython-examples/tree/master/pio/neopixel_ring/neopixel_ring.py
array, time
machine
import
Pin
rp2
16
6
0.2
ws2812():
T1 =
2
T2 =
5
T3 =
3
wrap_target()
label("bitloop")
out(x, 1)
.side(0)
jmp(not_x, "do_zero")
.side(1)
jmp("bitloop")
.side(1)
label("do_zero")
nop()
.side(0)
wrap()
[0
for
pixels_show():
dimmer_ar = array.array("I",
for
i,c in enumerate(ar):
r = int(((c >> 8) & 0xFF) * brightness)
g = int(((c >> 16) & 0xFF) * brightness)
b = int((c & 0xFF) * brightness)
dimmer_ar[i] = (g<<16) + (r<<8) + b
sm.put(dimmer_ar, 8)
time.sleep_ms(10)
pixels_set(i, color):
ar[i] = (color[1]<<16) + (color[0]<<8) + color[2]
pixels_fill(color):
for
i in range(len(ar)):
pixels_set(i, color)
[T3 - 1]
[T1 - 1]
[T2 - 1]
[T2 - 1]
_ in range(NUM_LEDS)])
[0
for
_ in range(NUM_LEDS)])
Lines 1 - 104
40
Need help?
Do you have a question about the Pico Python SDK and is the answer not in the manual?