from machine import Pin, ADC
from time import sleep
pot = ADC(Pin(34))
led = {
1: Pin(23, Pin.OUT),
2: Pin(22, Pin.OUT),
3: Pin(19, Pin.OUT),
4: Pin(18, Pin.OUT),
5: Pin(5, Pin.OUT),
6: Pin(17, Pin.OUT),
7: Pin(16, Pin.OUT),
8: Pin(4, Pin.OUT),
9: Pin(0, Pin.OUT),
10: Pin(2, Pin.OUT),
}
faixas = [
(409, 0),
(818, 1),
(1227, 2),
(1636, 3),
(2045, 4),
(2454, 5),
(2863, 6),
(3272, 7),
(3681, 8),
(4090, 9)
]
def apagar(pin):
for i in pin:
led[i].off()
def acender(num):
led[num].on()
for i in range(num + 1, 11):
led[i].off()
while True:
pot_value = pot.read()
print(pot_value)
if (pot_value < 409):
apagar([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
else:
for limite, y in faixas:
if pot_value <= limite:
acender(y)
break
else:
acender(10)
sleep(0.1)