"""
# Professor Cristiano Teixeira
# Sob Licença Apache 2.0
"""
"""
ET verde estilo 'grey' classico (cabeca grande cônica) - 32x32
Apenas a cabeça, olhos pretos grandes, boca fininha que abre em espanto.
Sem dentes.
Wokwi: ESP32 + wokwi-led-matrix 32x32
Conexao:
matrix:DIN -> esp:D2
matrix:VDD -> esp:3V3
matrix:VSS -> esp:GND
"""
import time
from machine import Pin
import neopixel
WIDTH = 32
HEIGHT = 32
PIN = 2
NUM_LEDS = WIDTH * HEIGHT # 1024
np = neopixel.NeoPixel(Pin(PIN), NUM_LEDS)
PRETO = (0, 0, 0)
VERDE = (0, 255, 0) # verde ET
OLHO = (0, 0, 0) # olhos pretos
BOCA = (0, 120, 0) # boca verde escura
def idx(x, y):
return y * WIDTH + x
def set_pixel(x, y, cor):
if 0 <= x < WIDTH and 0 <= y < HEIGHT:
np[idx(x, y)] = cor
def clear():
for i in range(NUM_LEDS):
np[i] = PRETO
def show():
np.write()
def sleep_ms(ms):
time.sleep_ms(ms)
# ---------- Cabeca grande cônica (larga em cima, afunila embaixo) ----------
cabeca = []
for y in range(2, 31):
if y <= 11:
raio = int(2 + (y -1 ) * 7 / 8) # alarga de 2 ate 7
else:
raio = int(12 - (y - 11) * 12 / 19) # afina de 12 ate 0
if raio < 1:
raio = 1
for x in range(16 - raio, 16 + raio + 1):
if 0 <= x < 32:
cabeca.append((x, y))
# ---------- Olhos grandes pretos ----------
olho_esq = []
olho_dir = []
for y in range(10, 19):
for x in range(7, 14):
dx = x - 11
dy = y - 13
if dx * dx + dy * dy <= 9:
olho_esq.append((x, y))
for y in range(10, 19):
for x in range(19, 26):
dx = x - 21
dy = y - 13
if dx * dx + dy * dy <= 9:
olho_dir.append((x, y))
# ---------- Boca fechada (dois pontinhos finos) ----------
boca_fechada = [(15, 23), (16, 23), (17, 23)]
# ---------- Boca aberta (ovale pequeno, sem dentes) ----------
boca_aberta = []
for y in range(22, 25):
for x in range(14, 19):
dx = x - 16
dy = y - 23
if dx * dx + dy * dy <= 4:
boca_aberta.append((x, y))
def desenhar(aberta=False):
clear()
# cabeca verde
for x, y in cabeca:
set_pixel(x, y, VERDE)
# olhos pretos grandes
for x, y in olho_esq:
set_pixel(x, y, OLHO)
for x, y in olho_dir:
set_pixel(x, y, OLHO)
# boca
if aberta:
for x, y in boca_aberta:
set_pixel(x, y, BOCA)
else:
for x, y in boca_fechada:
set_pixel(x, y, BOCA)
show()
# ---------- Teste rapido ----------
print("Teste: matriz verde...")
for i in range(NUM_LEDS):
np[i] = (0, 255, 0)
np.write()
time.sleep(1)
clear()
show()
print("ET iniciado")
# ---------- Loop ----------
while True:
desenhar(aberta=False) # boca fechada (dois pontinhos)
sleep_ms(900)
desenhar(aberta=True) # espanto! boca aberta
sleep_ms(900)