En la mayoría de las casas se estan utilizando sistemas donde se puede controlar la intensidad del foco desde un celular o desde la computadora. En esta práctica se realizará un control del brillo de un led desde el navegador.
/*
Creado: Luis Alvarez (edualv1723@gmail.com)
https://alvelectronics.com
*/
#include <WiFi.h>
#include <WebServer.h>
const char* ssid = "TuSSID";
const char* password = "TuPassword";
WebServer server(80);
const int dimmerPin = 14; // Pin PWM para el dimmer
int brillo = 0; // 0-255
void setBrillo(int value) {
ledcWrite(0, value);
}
void handleRoot() {
String html = "Control Dimmer ";
html += "Dimmer por WiFi - ESP32
";
html += "";
html += "Brillo: " + String(brillo) + "
";
html += "";
server.send(200, "text/html", html);
}
void handleSet() {
if (server.hasArg("value")) {
brillo = server.arg("value").toInt();
setBrillo(brillo);
Serial.printf("Brillo: %d\n", brillo);
}
server.send(200, "text/plain", "OK");
}
void setup() {
Serial.begin(115200);
// PWM en canal 0, frecuencia 5kHz, resoluci