import machine
import neopixel
import time

def wheel(pos):
    """Generate a color wheel value."""
    if pos < 85:
        return (pos * 3, 255 - pos * 3, 0)
    elif pos < 170:
        pos -= 85
        return (255 - pos * 3, 0, pos * 3)
    else:
        pos -= 170
        return (0, pos * 3, 255 - pos * 3)
    
led_pin = machine.Pin(3, machine.Pin.IN)

def read_led_data():
    """Read the data from the LED strip."""
    led_data = []
    for i in range(num_leds):
        led_data.append(np[i])
    return led_data

def smooth_rainbow(np, num_leds, delay=0.1):
    """Display a smooth rainbow on the LED strip."""
    for i in range(256):
        for j in range(num_leds):
            np[j] = wheel((i+j) & 255)
        np.write()
        print(read_led_data())
        time.sleep(delay)

# Configure the pin for the LED strip
pin = machine.Pin(10)
num_leds = 1  # Number of LEDs in the strip

# Create a neopixel object
np = neopixel.NeoPixel(pin, num_leds)

# Define the colors
colors = [
    (255, 0, 0),   # Red
    (0, 255, 0),   # Green
    (0, 0, 255),   # Blue
    (255, 255, 0), # Yellow
    (255, 0, 255), # Magenta
    (0, 255, 255)  # Cyan
]

# Flash all colors
while True:
    for color in colors:
        np[0] = color
        np.write()
        time.sleep(0.5)
        print(read_led_data())
    
    # Display a smooth rainbow
    smooth_rainbow(np, num_leds)