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

import	time
from	drivers_f	import	npxInit, npxShow, potmInit, potmGet

# ====================== 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')

npx        = npxInit()

def npxBar0():
    npxShow()
    
def npxBar1():
    npxShow(NPX_GREEN)
    
def npxBar2():
    npxShow(NPX_GREEN, NPX_GREEN)

def npxBar3():
    npxShow(NPX_YELLOW, NPX_YELLOW, NPX_YELLOW)

def npxBar4():
    npxShow(NPX_YELLOW, NPX_YELLOW, NPX_YELLOW, NPX_YELLOW)

def npxBar5():
    npxShow(NPX_RED, NPX_RED, NPX_RED, NPX_RED, NPX_RED)

def npxBar6():
    npxShow(NPX_RED, NPX_RED, NPX_RED, NPX_RED, NPX_RED, NPX_RED)

# ======================= Main ==============================
    
# print potmeter as value  -->  0.128 .. 3.126 [V]
def test1():
    potmInit()
    while True:
        time.sleep_ms(500)
        print(potmGet())
        
        
# sequence neopixel leds
def test2():
    while True:
        npxBar1(); time.sleep(1)
        npxBar2(); time.sleep(1)
        npxBar3(); time.sleep(1)
        npxBar4(); time.sleep(1)
        npxBar5(); time.sleep(1)
        npxBar6(); time.sleep(1)
        npxBar0(); time.sleep(1)


# the position of the potmeter controls the color and length of bar
def main():
    potmInit()
    while True:
        potm = potmGet()
        if   potm < 0.46: npxBar0()
        elif potm < 0.91: npxBar1()
        elif potm < 1.37: npxBar2()
        elif potm < 1.83: npxBar3()
        elif potm < 2.29: npxBar4()
        elif potm < 2.74: npxBar5()
        else            : npxBar6()
        time.sleep_ms(100)
        

#test1()
main()

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