from machine import Pin
from time import sleep_ms
from neopixel import NeoPixel

my_leds = NeoPixel(Pin(23), 16)

rgb_wave = [
  [255, 0, 0],
  [255, 127, 0],
  [255, 255, 0],
  [127, 255, 0],
  [0, 255, 0],
  [0, 255, 127],
  [0, 255, 255],
  [0, 127, 255],
  [0, 0, 255],
]

heat_wave = [
  [255, 0, 0],
  [255, 31, 0],
  [255, 63, 0],
  [255, 95, 0],
  [255, 127, 0],
  [255, 159, 0],
  [255, 191, 0],
  [255, 223, 0],
  [255, 255, 0]
]

green_wave = [
  [0, 255, 0],
  [0, 255, 31],
  [0, 255, 63],
  [0, 255, 95],
  [0, 255, 127],
  [0, 255, 159],
  [0, 255, 223],
  [0, 255, 255],
]

all_waves = rgb_wave + heat_wave + green_wave

def color_wave(leds, direc, wave, delay):
  if direc:
    i = 0
    inc = 1
    i_f = len(leds) + len(wave)

  else:
    i = len(leds) + len(wave) - 1
    inc = -1
    i_f = -2

  while i != i_f:
    for j in range(len(wave)):
      if i - j >= 0 and i - j < len(leds) and j < len(wave):
        if direc:
          leds[i - j] = wave[j]
        
        else:
          leds[i - j] = wave[len(wave) - 1 - j]

      if direc and i >= len(wave) and i - len(wave) < len(leds):
        leds[i - len(wave)] = [0, 0, 0]
      
      elif i < len(leds) - 1:
        leds[i + 1] = [0, 0, 0]
      
    i += inc

    leds.write()
    sleep_ms(delay)

while True:
  color_wave(my_leds, True, rgb_wave, 50)
  color_wave(my_leds, False, rgb_wave, 50)
  sleep_ms(2000)

  color_wave(my_leds, True, heat_wave, 50)
  color_wave(my_leds, False, heat_wave, 50)
  sleep_ms(2000)

  color_wave(my_leds, True, green_wave, 50)
  color_wave(my_leds, False, green_wave, 50)
  sleep_ms(2000)

  color_wave(my_leds, True, all_waves, 50)
  color_wave(my_leds, False, all_waves, 50)
  sleep_ms(2000)