# Kit FKS0001 demo - Potmeter - 6 NeoPixel Leds
# Provided by Anthony Vogelaar, Perth Scotland
# rev 0.10  2025-10-22  initial release

import	time
from	drivers	import	Potm, Npx

# =========================== Hardware ===========================

npx  = Npx(32)					# connect WS2812 with GPIO-32
potm = Potm(35)					# connect POTM   with GPIO-35

# ============================== main ============================

def main():
    intensities = [0]* 6
    while True:
        value = potm.get()						# value 0..3.20 Volt
        color = min(2, int(value))				# 0=green, 1=blue, 2=red
        for i in range(6):
            low   = 0.5 * i
            idx = int((value-low)/0.0625)		# 8 levels per division, 0.5 / 8 = 0.0625
            idx = max(0, idx)					# >= 0
            idx = min(7, idx)					# <= 7
            intensities[i] = (0, 1, 2, 4, 8, 16, 32, 128)[idx]	# evenly spread for human eye
        if   color == 0: npx_out = [bytes((x, 0, 0)) for x in intensities]		# green
        elif color == 1: npx_out = [bytes((0, 0, x)) for x in intensities]		# blue
        else:            npx_out = [bytes((0, x, 0)) for x in intensities]		# red
        npx.show(*npx_out)
        time.sleep_ms(20)						#  refresh rate 50 Hz


main()

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