#include #include #include #include #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 #define OLED_RESET -1 #define SCREEN_ADDRESS 0x3C Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); #define RED_PIN 4 #define GREEN_PIN 5 #define BLUE_PIN 6 #define BUZZER_PIN 19 const char* ssid = "ESP32-AP"; const char* password = "12345678"; WebServer server(80); // ======================= HTML ======================== const char* html = R"rawliteral( SAFETY CONTROL PANEL

🛠️ Fabsafe Interface

🔴 LED RGB Control

📟 OLED Display

)rawliteral"; // ================ FUNCIONES DE SERVIDOR ================== void handleRoot() { server.send(200, "text/html", html); } void handleLedOff() { analogWrite(RED_PIN, 255); analogWrite(GREEN_PIN, 255); analogWrite(BLUE_PIN, 255); server.send(200, "text/plain", "LED apagado"); } void handleLedRandom() { analogWrite(RED_PIN, 255 - random(0, 256)); analogWrite(GREEN_PIN, 255 - random(0, 256)); analogWrite(BLUE_PIN, 255 - random(0, 256)); tone(BUZZER_PIN, 1500, 100); server.send(200, "text/plain", "Color aleatorio"); } void handleOledOff() { display.clearDisplay(); display.display(); server.send(200, "text/plain", "Pantalla apagada"); } void handleOledHappy() { display.clearDisplay(); display.setTextSize(3); display.setTextColor(WHITE); display.setCursor(40, 0); display.print(":)"); display.setTextSize(1); display.setCursor(0, 50); display.print("Modo: FELIZ"); display.display(); server.send(200, "text/plain", "Feliz"); } void handleOledSad() { display.clearDisplay(); display.setTextSize(3); display.setTextColor(WHITE); display.setCursor(40, 0); display.print(":("); display.setTextSize(1); display.setCursor(0, 50); display.print("Modo: TRISTE"); display.display(); server.send(200, "text/plain", "Triste"); } void handleOledPoker() { display.clearDisplay(); display.setTextSize(3); display.setTextColor(WHITE); display.setCursor(25, 0); display.print(":|"); display.setTextSize(1); display.setCursor(0, 50); display.print("Modo: POKER FACE"); display.display(); server.send(200, "text/plain", "Poker face"); } void setup() { Serial.begin(115200); WiFi.softAP(ssid, password); Serial.println(WiFi.softAPIP()); pinMode(RED_PIN, OUTPUT); pinMode(GREEN_PIN, OUTPUT); pinMode(BLUE_PIN, OUTPUT); pinMode(BUZZER_PIN, OUTPUT); // OLED Wire.begin(21, 20); // SDA = 21, SCL = 20 if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("Fallo pantalla OLED")); while (true); } display.clearDisplay(); display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(0, 0); display.print("Sistema listo"); display.display(); // Servidor server.on("/", handleRoot); server.on("/led/off", handleLedOff); server.on("/led/random", handleLedRandom); server.on("/oled/off", handleOledOff); server.on("/oled/happy", handleOledHappy); server.on("/oled/sad", handleOledSad); server.on("/oled/poker", handleOledPoker); server.begin(); } void loop() { server.handleClient(); }