from machine import Pin, ADC, I2C
import utime
from pico_i2c_lcd import I2cLcd
# Configuração do LCD (endereços comuns: 0x27 ou 0x3F)
i2c = I2C(0, scl=Pin(5), sda=Pin(4), freq=400000)
lcd = I2cLcd(i2c, 0x27, 2, 16)
# Configuração do potenciômetro e botão
pot = ADC(26) # Pino ADC0
botao = Pin(14, Pin.IN, Pin.PULL_DOWN)
# Opções do menu
opcoes = ["Ver hora", "Abrir Google", "Acender LED", "Sair"]
indice = 0
selecionado = False
def mostrar_menu(indice):
lcd.clear()
lcd.putstr("Menu:\n")
for i, opcao in enumerate(opcoes):
prefixo = ">" if i == indice else " "
lcd.putstr(f"{prefixo}{opcao}\n" if i == indice else f" {opcao}\n")
# Loop principal
lcd.clear()
lcd.putstr("Assistente\nCarregando...")
utime.sleep(2)
while True:
# Lê valor do potenciômetro (0 a 65535) e converte para índice
valor = pot.read_u16()
indice = int((valor / 65535) * (len(opcoes) - 1))
mostrar_menu(indice)
if botao.value() == 1:
lcd.clear()
lcd.putstr(f"Selecionado:\n{opcoes[indice]}")
utime.sleep(1.5)
if opcoes[indice] == "Sair":
lcd.clear()
lcd.putstr("Encerrando...")
break
utime.sleep(0.2)