from machine import Pin, ADC
import network
import time
SSID = "Wokwi-GUEST"
PASSWORD = ""
pot = ADC(26)
led = Pin(18, Pin.OUT)
buzzer = Pin(13, Pin.OUT)
print("Conectando ao Wi-Fi...")
wifi = network.WLAN(network.STA_IF)
wifi.active(True)
wifi.connect(SSID, PASSWORD)
while not wifi.isconnected():
print(".", end="")
time.sleep(0.5)
print()
print("Wi-Fi conectado!")
ip = wifi.ifconfig()[0]
print("IP Obtido:", ip)
print("--------------------")
while True:
ad = pot.read_u16()
porcent = int((ad / 65535) * 100)
if porcent > 50:
led.on()
estado_led = "LIGADO"
else:
led.off()
estado_led = "DESLIGADO"
if porcent > 80:
buzzer.on()
estado_buzzer = "LIGADO"
else:
buzzer.off()
estado_buzzer = "DESLIGADO"
print("Relatorio")
print("IP:", ip)
print("ADC:", ad)
print("Nivel:", str(porcent) + "%")
print("LED:", estado_led)
print("BUZZER:", estado_buzzer)
print("--------------------")
print()
time.sleep(2)