import sys if "lib" not in sys.path: sys.path.insert(0, "lib") if "../lib" not in sys.path: sys.path.insert(0, "../lib") from ws2812 import WS2812B import time # --- Chase test: pregenerated double buffer per strip, show via head offset (same as rainbow) --- # (pin, num_leds) per strip — same config as rainbow STRIP_CONFIG = ( (2, 291), (3, 290), (4, 283), (7, 278), (0, 275), (28, 278), (29, 283), (6, 290), ) strips = [] sm = 0 for pin, num_leds in STRIP_CONFIG: print(pin, num_leds) ws = WS2812B(num_leds, pin, sm, brightness=1.0) strips.append(ws) sm += 1 cumulative_leds = [0] for ws in strips[:-1]: cumulative_leds.append(cumulative_leds[-1] + ws.num_leds) total_ring_leds = cumulative_leds[-1] + strips[-1].num_leds # Chase: color1 n1 long, then color2 n2 long, stepping n3 pixels COLOR1 = (255, 0, 0) # red COLOR2 = (0, 0, 255) # blue N1 = 24 # length of color1 segment N2 = 24 # length of color2 segment STEP = 1 # step size in pixels per frame def make_chase_double(num_leds, cumulative_leds, total_ring_leds, color1, color2, n1, n2): """Pregenerate strip double buffer with repeating segments: color1 for n1 pixels, then color2 for n2 pixels, around the full ring. GRB order.""" n = 2 * num_leds buf = bytearray(n * 3) pattern_len = n1 + n2 for b in range(n): # Position of this pixel along the logical ring pos = (2 * cumulative_leds - b) % total_ring_leds seg_pos = pos % pattern_len if seg_pos < n1: r, grn, b_ = color1[0], color1[1], color1[2] else: r, grn, b_ = color2[0], color2[1], color2[2] o = b * 3 buf[o] = grn buf[o + 1] = r buf[o + 2] = b_ return buf # Pregenerate one double buffer per strip chase_buffers = [ make_chase_double(ws.num_leds, cumulative_leds[i], total_ring_leds, COLOR1, COLOR2, N1, N2) for i, ws in enumerate(strips) ] chase_pos = 0 while True: for i, strip in enumerate(strips): # head in [0, strip_len) so DMA read head..head+num_leds*3 stays in double buffer (same as rainbow) strip_len = strip.num_leds * 3 head = (chase_pos + cumulative_leds[i]) * 3 % strip_len strip.show(chase_buffers[i], head) chase_pos = (chase_pos + STEP) % total_ring_leds time.sleep_ms(40)