"""Module 02: cycle the five WS2812 LEDs on GP14 through eight colours."""

import time
import board
import busio
import neopixel
import adafruit_ssd1306


COLOURS = (
    ("RED", (255, 0, 0)),
    ("ORANGE", (255, 180, 0)),
    ("YELLOW", (80, 80, 0)),
    ("GREEN", (0, 255, 0)),
    ("CYAN", (0, 255, 255)),
    ("BLUE", (0, 0, 255)),
    ("PURPLE", (180, 0, 255)),
    ("WHITE", (100, 100, 100)),
)

i2c = busio.I2C(board.GP5, board.GP4)
oled = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3C)
pixels = neopixel.NeoPixel(board.GP14, 5, brightness=0.1, auto_write=True)

try:
    while True:
        for name, colour in COLOURS:
            pixels.fill(colour)
            oled.fill(0)
            oled.text('(2) NeoPixel RGB', 0, 0, 1)
            oled.text('Data: GP14', 0, 16, 1)
            oled.text('LED count: 5', 0, 28, 1)
            oled.text('Colour: ' + name, 0, 40, 1)
            oled.show()
            print("Colour:", name)
            time.sleep(0.8)
finally:
    pixels.fill((0, 0, 0))
    pixels.deinit()
    i2c.deinit()
