// ─── Configuración ──────────────────────────────────────────────────────────── const int LED_PIN = D3; // LED integrado const long BAUDRATE = 115200; // ────────────────────────────────────────────────────────────────────────────── String inputBuffer = ""; bool messageReady = false; void setup() { Serial.begin(BAUDRATE); pinMode(LED_PIN, OUTPUT); Serial.println("[ARDUINO] Listo. Esperando comandos..."); } void loop() { // ── Leer datos entrantes ── while (Serial.available()) { char c = Serial.read(); if (c == '\n') { messageReady = true; } else { inputBuffer += c; } } // ── Procesar mensaje completo ── if (messageReady) { inputBuffer.trim(); procesarComando(inputBuffer); inputBuffer = ""; messageReady = false; } } void procesarComando(String cmd) { // ── Comandos disponibles ── if (cmd == "LED_ON") { digitalWrite(LED_PIN, HIGH); Serial.println("[OK] LED encendido"); } else if (cmd == "LED_OFF") { digitalWrite(LED_PIN, LOW); Serial.println("[OK] LED apagado"); } else if (cmd == "PING") { Serial.println("[PONG]"); } else if (cmd == "STATUS") { Serial.print("[STATUS] LED = "); Serial.println(digitalRead(LED_PIN) ? "ON" : "OFF"); } else { Serial.print("[WARN] Comando desconocido: "); Serial.println(cmd); } }