# Controls an addressable WS2812B (NeoPixel) RGB LED on Raspberry Pi Pico / YD-RP2040 (GP23).

import machine
import neopixel
import time

# Pin configuration and pixel count
PIXEL_PIN = 23
NUM_PIXELS = 1

# Initialize GPIO pin for digital output and instantiate NeoPixel driver
pin = machine.Pin(PIXEL_PIN, machine.Pin.OUT)
np = neopixel.NeoPixel(pin, NUM_PIXELS)

# Define color sequence in (Red, Green, Blue) format with values 0 to 255
# Using low brightness values to avoid eye strain
colorsToShow = [
    (20,  0,  0),  # Red (e.g., alarm / tachyarrhythmia indication)
    ( 0, 20,  0),  # Green (e.g., normal status / detected QRS complex)
    ( 0,  0, 20),  # Blue (e.g., active Bluetooth / recording)
    (20, 20,  0),  # Yellow (e.g., warning / lead-off contact instability)
    (20,  0, 20),  # Purple
    ( 0, 20, 20),  # Cyan
    ( 0,  0,  0)   # Off
]

print("Starting WS2812B NeoPixel RGB LED color demonstration...")

while True:
    for color in colorsToShow:
        # Set color for the first pixel (index 0)
        np[0] = color
        
        # Transmit color data packet to LED over single-wire protocol
        np.write()
        
        print(f"Active color (R, G, B): {color}")
        time.sleep(1)  # 1-second delay between colors
