import machine
import neopixel
import time
from random import randint
LED_PIN = 15
NUM_LEDS = 16
POT1_PIN = 26
POT2_PIN = 27
np = neopixel.NeoPixel(machine.Pin(LED_PIN), NUM_LEDS)
pot1 = machine.ADC(machine.Pin(POT1_PIN))
pot2 = machine.ADC(machine.Pin(POT2_PIN))
# Функция для получения значения потенциометра
# Возвращает нормализованное значение в заданном диапазоне
def read_pot(pot, min_val, max_val):
return min_val + (pot.read_u16() * (max_val - min_val) // 65535)
while True:
# Чтение значений потенциометров
num_blinking = int(read_pot(pot1, 1, NUM_LEDS))
blink_delay = read_pot(pot2, 50, 1000) / 1000
np.fill((0, 0, 0))
for _ in range(num_blinking):
led_index = randint(0, NUM_LEDS - 1)
color = (
255,
0,
0
)
np[led_index] = color
np.write()
time.sleep(blink_delay)
np[led_index] = (0,0,0)
np.write()