from machine import Pin, ADC, PWM
from utime import sleep
import time
rojo = Pin(15, Pin.OUT)
verde = Pin(2, Pin.OUT)
sens_adc = ADC(Pin(39))
buzz = PWM(Pin(4))
def sonido(duty):
buzz.duty(512)
while True:
lectura = sens_adc.read_u16()
valor = 3.3 / 65535
voltaje = lectura * valor
print("Resolución: {:.2f}".format(lectura), "Voltaje: {:.2f}V".format(voltaje))
sleep(0.2)
if voltaje <= 2:
verde.value(1)
rojo.value(0)
buzz.duty(0)
else:
rojo.value(1)
verde.value(0)
buzz.duty(512)