from machine import Pin, I2C
import ssd1306
import network
import time
# ---------------- CONFIGURACIÓN ----------------
SSID = "PON_AQUI_EL_NOMBRE_DE_TU_WIFI"
PASSWORD = "PON_AQUI_TU_CONTRASEÑA"
# Pantalla OLED 0.96" 128x64
ANCHO = 128
ALTO = 64
i2c = I2C(0, scl=Pin(22), sda=Pin(21), freq=400000)
pantalla = ssd1306.SSD1306_I2C(ANCHO, ALTO, i2c)
# ---------------- FUNCIONES DE DIBUJO ----------------
def limpiar():
pantalla.fill(0)
pantalla.show()
def mostrar_cara_neutra():
limpiar()
# Ojos
pantalla.fill_circle(42, 22, 9, 1)
pantalla.fill_circle(86, 22, 9, 1)
# Boca
pantalla.fill_rect(52, 44, 26, 4, 1)
pantalla.show()
def mostrar_cara_feliz():
limpiar()
pantalla.fill_circle(42, 22, 9, 1)
pantalla.fill_circle(86, 22, 9, 1)
# Boca sonriente
for x in range(50, 80):
y = int(45 + ((x - 65) ** 2) / 60)
pantalla.pixel(x, y, 1)
pantalla.pixel(x+1, y, 1)
pantalla.show()
def parpadear_ojos():
# Ojos cerrados
limpiar()
pantalla.fill_rect(33, 20, 18, 4, 1)
pantalla.fill_rect(77, 20, 18, 4, 1)
pantalla.fill_rect(52, 44, 26, 4, 1)
pantalla.show()
time.sleep(0.2)
# Ojos abiertos
limpiar()
pantalla.fill_circle(42, 22, 9, 1)
pantalla.fill_circle(86, 22, 9, 1)
pantalla.fill_rect(52, 44, 26, 4, 1)
pantalla.show()
# ---------------- CONECTAR WIFI ----------------
def conectar_wifi():
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
if not wlan.isconnected():
print("Conectando a", SSID, "...")
wlan.connect(SSID, PASSWORD)
while not wlan.isconnected():
time.sleep(0.5)
print(".", end="")
print("\n✅ WiFi conectado!")
print("📡 IP:", wlan.ifconfig()[0])
return wlan
# ---------------- PROGRAMA PRINCIPAL ----------------
print("Iniciando...")
limpiar()
pantalla.text("Iniciando...", 25, 25)
pantalla.show()
conectar_wifi()
mostrar_cara_feliz()
# Bucle principal
while True:
parpadear_ojos()
time.sleep(4)Loading
esp32-devkit-c-v4
esp32-devkit-c-v4
Loading
ssd1306
ssd1306