# Esp32 - Driver for 6 NeoPixel Leds on kit FKS0001
# provided by Anthony Vogelaar, Perth Scotland
# rev 0.10  2025-06-19  initial release

from 	machine 	import 	Pin, freq;		freq(240_000_000)
import	time
import	neopixel	as		npx

# Implemented:
# npxInit(pin=25)
# npxSetLeds(l0=NPX_OFF, l1=NPX_OFF, l2=NPX_OFF, l3=NPX_OFF, l4=NPX_OFF, l5=NPX_OFF)

# ========================= Neo Pixel Leds ===========================

npx_leds = None

# Basic colours for Neopixel LED's WS2812
NPX_OFF    = bytes.fromhex('00 00 00')
NPX_GREEN  = bytes.fromhex('FF 00 00')
NPX_RED    = bytes.fromhex('00 FF 00')
NPX_BLUE   = bytes.fromhex('00 00 FF')
NPX_YELLOW = bytes.fromhex('FF FF 00')
NPX_WHITE  = bytes.fromhex('FF FF FF')


# Setup of NeoPixel LED output
def npxInit(pin=25):
    global npx_leds
    npx_leds = npx.NeoPixel(Pin(25), 6)		# Setup for 6 leds on pin


# Set the colours of the 6 NeoPixel LED's
def npxShow(l0=NPX_OFF, l1=NPX_OFF, l2=NPX_OFF, l3=NPX_OFF, l4=NPX_OFF, l5=NPX_OFF):
    npx_leds[0] = l0; npx_leds[1] = l1; npx_leds[2] = l2
    npx_leds[3] = l3; npx_leds[4] = l4; npx_leds[5] = l5
    npx_leds.write()
    
# ===================== Tests ========================

def test():
    npxInit()
    while True:
        npxShow(NPX_GREEN);   time.sleep(1)
        npxShow(l1=NPX_RED);  time.sleep(1)
        npxShow(l2=NPX_BLUE); time.sleep(1)


test()

# ===================== End =========================
