#include <WiFi.h>
#include <WebServer.h>
const char* ssid = "Familia Ramirez Rodriguez";
const char* password = "35354681julu";
// Pines de los segmentos y las líneas de display
const int segmentos[] = { 2, 4, 5, 12, 13, 14, 27, 26 };
const int displayLines[4] = { 15, 18, 19, 21 };
// Instancia del servidor web en el puerto 80
WebServer server(80);
void inicializarDisplay() {
for (int i = 0; i < 8; i++) {
pinMode(segmentos[i], OUTPUT);
digitalWrite(segmentos[i], LOW);
}
for (int j = 0; j < 4; j++) {
pinMode(displayLines[j], OUTPUT);
digitalWrite(displayLines[j], LOW);
}
}
// Mostrar un número en una línea de display
void mostrarNumero(int numero, int linea) {
const int numeros[10][8] = {
{1, 1, 1, 1, 1, 1, 0, 0}, {0, 1, 1, 0, 0, 0, 0, 0},
{1, 1, 0, 1, 1, 0, 1, 0}, {1, 1, 1, 1, 0, 0, 1, 0},
{0, 1, 1, 0, 0, 1, 1, 0}, {1, 0, 1, 1, 0, 1, 1, 0},
{1, 0, 1, 1, 1, 1, 1, 0}, {1, 1, 1, 0, 0, 0, 0, 0},
{1, 1, 1, 1, 1, 1, 1, 0}, {1, 1, 1, 1, 0, 1, 1, 0}
};
for (int i = 0; i < 4; i++) digitalWrite(displayLines[i], LOW);
digitalWrite(displayLines[linea], HIGH);
for (int i = 0; i < 8; i++) digitalWrite(segmentos[i], numeros[numero][i]);
delay(5);
}
// Página HTML para enviar el número
String paginaWeb() {
String html = "<!DOCTYPE html><html lang='es'>";
html += "<head><meta name='viewport' content='width=device-width, initial-scale=1'>";
html += "<title>Control de Display</title></head><body>";
html += "<h1>Enviar Número a Display</h1>";
html += "<form action='/enviar' method='POST'>";
html += "<label for='numero'>Número (0-9):</label>";
html += "<input type='number' id='numero' name='numero' min='0' max='9'>";
html += "<input type='submit' value='Enviar'></form></body></html>";
return html;
}
// Procesar el envío del formulario
void manejarEnvio() {
if (server.hasArg("numero")) {
int numero = server.arg("numero").toInt();
for (int i = 0; i < 4; i++) {
mostrarNumero(numero, i); // Muestra el mismo número en cada línea de display
}
server.send(200, "text/html", "<p>Número mostrado en el display.</p><a href='/'>Regresar</a>");
} else {
server.send(400, "text/plain", "Número no válido.");
}
}
void setup() {
Serial.begin(115200);
inicializarDisplay();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) delay(500);
server.on("/", []() { server.send(200, "text/html", paginaWeb()); });
server.on("/enviar", HTTP_POST, manejarEnvio);
server.begin();
}
void loop() {
server.handleClient();
}