import machine
import neopixel
import urandom
import utime
# Define the number of pixels in each ring
NUM_PIXELS_RING1 = 12
NUM_PIXELS_RING2 = 16
# Define the pin numbers for the neopixel rings
PIN_RING1 = machine.Pin(12)
PIN_RING2 = machine.Pin(13)
# Create neopixel objects for each ring
pixels_ring1 = neopixel.NeoPixel(PIN_RING1, NUM_PIXELS_RING1)
pixels_ring2 = neopixel.NeoPixel(PIN_RING2, NUM_PIXELS_RING2)
# Function to generate a random RGB color
def random_color():
return (urandom.randint(0, 255), urandom.randint(0, 255), urandom.randint(0, 255))
# Function to shift the colors in the given ring by one position clockwise
def shift_colors_clockwise(pixels):
last_pixel = pixels[-1]
for i in range(len(pixels) - 1, 0, -1):
pixels[i] = pixels[i - 1]
pixels[0] = last_pixel
# Function to shift the colors in the given ring by one position counterclockwise
def shift_colors_counterclockwise(pixels):
first_pixel = pixels[0]
for i in range(len(pixels) - 1):
pixels[i] = pixels[i + 1]
pixels[-1] = first_pixel
# Main program loop
while True:
# Update ring 1 colors
shift_colors_clockwise(pixels_ring1)
pixels_ring1[0] = random_color()
pixels_ring1.write()
# Update ring 2 colors
shift_colors_counterclockwise(pixels_ring2)
pixels_ring2[-1] = random_color()
pixels_ring2.write()
# Delay for a short period of time before updating again
utime.sleep(0.1)