from machine import Pin, ADC, PWM
import time
class BarLed:
def __init__(self, pin, minVal, maxVal) -> None:
self.led=Pin(pin, Pin.OUT)
self.minVal=minVal
self.maxVal=maxVal
def refresh(self, val):
if(self.minVal <= val <= self.maxVal):
self.led.on()
else:
self.led.off()
class LedBar:
def __init__(self,l1,l2,l3,l4,l5) -> None:
self.bar={l1,l2,l3,l4,l5}
def refresh(self, val):
for led in self.bar:
led.refresh(val)
led_green1=BarLed(33, 1, 1023)
led_green2=BarLed(25, 200, 1023)
led_yellow1=BarLed(26, 400, 1023)
led_yellow2=BarLed(27, 600, 1023)
led_red=BarLed(14, 800, 1023)
ledBar=LedBar(led_green1, led_green2, led_yellow1, led_yellow2, led_red)
potenziometro = ADC(Pin(32))
potenziometro.atten(ADC.ATTN_11DB)
vmaxi = 4095
vmaxo = 1023
buzzer = PWM (Pin(15, Pin.OUT), 700)
while True:
valorePotenziometro=potenziometro.read()
duty=(int) (valorePotenziometro *vmaxo / vmaxi)
print(duty)
buzzer.duty(duty)
ledBar.refresh(duty)