# mPy - neopixel demonstration on ESP32 pin 25 with timer
# Provided by Anthony Vogelaar, Perth Scotland
# rev 0.10  2025-05-20  initial release

from	machine		import	Pin
import	time
from	array		import	array
import	neopixel	as		npx

# ================== Neopixel constants ===========================

GREEN   = array('i', [255,   0,   0])		# 'i' is 32 bit int
RED     = array('i', [  0, 255,   0])
BLUE    = array('i', [  0,   0, 255])
YELLOW  = array('i', [255, 255,   0])
MAGENTA = array('i', [  0, 255, 255])
CYAN    = array('i', [255,   0, 255])
WHITE   = array('i', [255, 255, 255])
OFF     = array('i', [  0,   0,   0])

# ====================== Hardware setup ===========================

leds = npx.NeoPixel(Pin(25), 6)		# Setup for 6 ledss on Pin 25

# ========================== Local ================================

col = GREEN

def pos_0():
    leds[0]=col; leds[1]=OFF; leds[2]=OFF; leds[3]=OFF; leds[4]=OFF; leds[5]=OFF
    leds.write()
    
def pos_1():
    leds[0]=OFF; leds[1]=col; leds[2]=OFF; leds[3]=OFF; leds[4]=OFF; leds[5]=OFF
    leds.write()


def pos_2():
    leds[0]=OFF; leds[1]=OFF; leds[2]=col; leds[3]=OFF; leds[4]=OFF; leds[5]=OFF
    leds.write()


def pos_3():
    leds[0]=OFF; leds[1]=OFF; leds[2]=OFF; leds[3]=col; leds[4]=OFF; leds[5]=OFF
    leds.write()


def pos_4():
    leds[0]=OFF; leds[1]=OFF; leds[2]=OFF; leds[3]=OFF; leds[4]=col; leds[5]=OFF
    leds.write()


def pos_5():
    leds[0]=OFF; leds[1]=OFF; leds[2]=OFF; leds[3]=OFF; leds[4]=OFF; leds[5]=col
    leds.write()

# =========================== Main ================================

def main():
    dly = 1000
    while True:
        pos_0(); time.sleep_ms(dly)
        pos_1(); time.sleep_ms(dly)
        pos_2(); time.sleep_ms(dly)
        pos_3(); time.sleep_ms(dly)
        pos_4(); time.sleep_ms(dly)
        pos_5(); time.sleep_ms(dly)
    
    
main()

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