# HCC home-work 2025-06-26 Npx alarm bar set by potm using classes
# Provided by Anthony Vogelaar, Perth Scotland
#rev 0.10  2025-06-26  initial release

import	time
from	drivers	import	Npx, Potm

# ====================== Neo pixels ========================

# Npx colors with adjusted intensity for camera
NPX_OFF    = bytes.fromhex('00 00 00')
NPX_GREEN  = bytes.fromhex('10 00 00')
NPX_YELLOW = bytes.fromhex('08 08 00')
NPX_RED    = bytes.fromhex('00 10 00')

BAR0 = []
BAR1 = [NPX_GREEN]
BAR2 = [NPX_GREEN, NPX_GREEN]
BAR3 = [NPX_YELLOW, NPX_YELLOW, NPX_YELLOW]
BAR4 = [NPX_YELLOW, NPX_YELLOW, NPX_YELLOW, NPX_YELLOW]
BAR5 = [NPX_RED, NPX_RED, NPX_RED, NPX_RED, NPX_RED]
BAR6 = [NPX_RED, NPX_RED, NPX_RED, NPX_RED, NPX_RED, NPX_RED]

BARS = [BAR0, BAR1, BAR2, BAR3, BAR4, BAR5, BAR6]

# ====================== Potmeter ===========================

# provide potm position as index 0..6
def potmAsIdx(potm):
    val = potm.get()
    return int(val / (3.2 / 7))

# ======================= Main ==============================
    
# print potmeter as index  -->  0 .. 6
def test1():
    potm = Potm()
    while True:
        time.sleep_ms(500)
        print(potmAsIdx(potm))
        
        
# sequence neopixel leds
def test2():
    npx = Npx()
    while True:
        npx.show(*BAR1); time.sleep(1)
        npx.show(*BAR2); time.sleep(1)
        npx.show(*BAR3); time.sleep(1)
        npx.show(*BAR4); time.sleep(1)
        npx.show(*BAR5); time.sleep(1)
        npx.show(*BAR6); time.sleep(1)
        npx.show(*BAR0); time.sleep(1)


# sequence neopixel leds with unpacking list
def test3():
    npx = Npx()
    while True:
        for i in range(7):
            npx.show(*BARS[i])
            time.sleep(1)


# potmeter adjusts alarm neopixel bar
def main():
    npx  = Npx()
    potm = Potm()
    while True:
        idx = potmAsIdx(potm)
        npx.show(*BARS[idx])
        time.sleep_ms(100)
        

#test1()
main()

# ========================= end ==============================
