from machine import Pin
from neopixel import NeoPixel
import time

# Definitions for the ATOM Matrix
LED_GPIO = const(27)
matrix_size_x = const(5)
matrix_size_y = const(5)
is_atom_matrix = True

np = NeoPixel(Pin(LED_GPIO), matrix_size_x * matrix_size_y)
n=25
def wheel(pos):
  if pos < 0 or pos > 255:
    return (0, 0, 0)
  if pos < 85:
    return (255 - pos * 3, pos * 3, 0)
  if pos < 170:
    pos -= 85
    return (0, 255 - pos * 3, pos * 3)
  pos -= 170
  return (pos * 3, 0, 255 - pos * 3)

def rainbow_cycle(wait):
  for j in range(255):
    for i in range(n):
      rc_index = (i * 256 // n) + j
      np.fill(wheel(rc_index & 255))
    np.write()
    time.sleep_ms(wait)

while True:
    rainbow_cycle(30)