import gc
from machine import Pin, SPI
import max7219
import framebuf
import network
import socket
spi = SPI(1, baudrate=10000000, polarity=0, phase=0, sck=Pin(18), mosi=Pin(23))
cs = Pin(5, Pin.OUT)
display = max7219.Matrix8x8(spi, cs, 4)
ap = network.WLAN(network.AP_IF)
ap.active(True)
ap.config(essid="CoDIY", password="12345678")
print("Rede ativa. Acesse:", ap.ifconfig()[0])
Y = [0, 1, 2, 3, 4, 5, 6, 7]
X = [
[6,7,8,9,10],
[5,6,7,8,9,10,11],
[5,6,7,8,9,10,11],
[5,6,7,8,9,10,11],
[5,6,7,8,9,10,11],
[5,6,7,8,9,10,11],
[5,6,7,8,9,10,11],
[6,7,8,9,10]
]
Y2 = [0, 1, 2, 3, 4, 5, 6, 7]
X2 = [
[20,21,22,23,24],
[19,20,21,22,23,24,25],
[19,20,21,22,23,24,25],
[19,20,21,22,23,24,25],
[19,20,21,22,23,24,25],
[19,20,21,22,23,24,25],
[19,20,21,22,23,24,25],
[20,21,22,23,24]
]
Y3= [0,1,2,3,4,5,6,7]
X3= [
[4],
[4,5],
[4,5,6],
[4,5,6,7],
[4,5,6,7],
[4,5,6],
[4,5],
[4]
]
Y4= [0,1,2,3,4,5,6,7]
X4= [
[27],
[27,26],
[27,26,25],
[27,26,25,24],
[27,26,25,24],
[27,26,25],
[27,26],
[27]
]
def pagina_html():
return """<!DOCTYPE html>
<html>
<head>
<title>Escolha de cara</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}
h1 {
margin-bottom: 40px;
}
button {
width: 150px;
height: 60px;
font-size: 24px;
margin: 15px;
cursor: pointer;
border-radius: 10px;
border: 2px solid #444;
background-color: #ddd;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #bbb;
}
form {
display: inline-block;
}
</style>
</head>
<body>
<h1>Escolha de cara</h1>
<form action="/Felix"><button>Felix</button></form>
<form action="/Triste"><button>Triste</button></form>
<form action="/Bravo"><button>Bravo</button></form>
<form action="/Normal"><button>Normal</button></form>
</body>
</html>"""
s = socket.socket()
s.bind(('0.0.0.0', 80))
s.listen(1)
def Expressoes():
conn, addr = s.accept()
print("Conectado por:", addr)
request = conn.recv(1024).decode('utf-8')
print("Requisição:", request)
display.fill(0)
if '/Normal' in request:
for idx in range(len(Y)):
y = Y[idx]
for x in X[idx]:
display.pixel(x, y, 1)
for idx in range(len(Y2)):
y2 = Y2[idx]
for x2 in X2[idx]:
display.pixel(x2, y2, 1)
display.show()
elif '/Bravo' in request:
for idx in range(len(Y3)):
y3 = Y3[idx]
for x3 in X3[idx]:
display.pixel(x3, y3, 1)
for idx in range(len(Y4)):
y4 = Y4[idx]
for x4 in X4[idx]:
display.pixel(x4, y4, 1)
display.show()
elif '/Felix' in request:
buf = bytearray(32 * 8 // 8)
fb = framebuf.FrameBuffer(buf, 32, 8, framebuf.MONO_HLSB)
fb.fill(0)
fb.line(7, 1, 1, 7, 1)
fb.line(8, 1, 14, 7, 1)
fb.line(23, 1, 17, 7, 1)
fb.line(24, 1, 30, 7, 1)
display.blit(fb, 0, 0)
display.show()
elif '/Triste' in request:
buf = bytearray(32 * 8 // 8)
fb = framebuf.FrameBuffer(buf, 32, 8, framebuf.MONO_HLSB)
fb.fill(0)
fb.line(0, 0, 7, 7, 1)
fb.line(0, 7, 7, 0, 1)
fb.line(24, 0, 31, 7, 1)
fb.line(31, 0, 24, 7, 1)
display.blit(fb, 0, 0)
display.show()
resposta = pagina_html()
conn.send('HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n')
conn.send(resposta)
conn.close()
while True:
Expressoes()
gc.collect()