# https://www.instructables.com/Respberry-Pi-Pico-W-NeoPixels-Experiments-With-Pro/ import time import rp2 from machine import Pin @rp2.asm_pio(set_init=rp2.PIO.OUT_LOW, out_shiftdir=rp2.PIO.SHIFT_LEFT) def neo_prog(): pull() # osr <= number of pixels - 1 mov(y, osr) # y <= number of pixels - 1 label("loop_pixel") mov(isr, y) # isr (pixel counter) <= y pull() # osr <= 24 bits GRB set(x, 23) # x (bit counter) <= 23 label("loop_pixel_bit") out(y, 1) # y <= left-most 1 bit of osr jmp(not_y, "bit_0") set(pins, 1).delay(13) # 1: high (7 cycles) set(pins, 0).delay(9) # 1: low (5 cycles) jmp("bit_end") label("bit_0") set(pins, 1).delay(5) # 0: high (3 cycles) set(pins, 0).delay(17) # 0: low (9 cycles) label("bit_end") jmp(x_dec, "loop_pixel_bit") # x is bit counter mov(y, isr) # y <= isr (pixel counter) jmp(y_dec, "loop_pixel") # y is pixel counter sm = rp2.StateMachine(0, neo_prog, freq=20_000_000, set_base=Pin(12)) sm.active(1) Pixels = [] for i in range(16): Pixels.append((i,0,0)) x = 0 N = 16 while(1): x = (x + 1) % 256 sm.put(N-1) for i in range(0,N): g = 0; r = (i*5 + x) % 80; b = 80 - r; grb = (g << 16) + (r << 8) + b sm.put(grb << 8) time.sleep(0.05)