miércoles, 2 de septiembre de 2026

LED CONTROL

 #define LED 2


void setup() {
  pinMode(LED, OUTPUT);

  Serial.begin(115200);
  Serial.println("=== Hello ===");
  Serial.println("=== ESP32 LED CONTROL ===");
  Serial.println("Type ON to turn the LED ON");
  Serial.println("Type OFF to turn the LED OFF");
}

void loop() {

  if (Serial.available() > 0) {

    String command = Serial.readStringUntil('\n');
    command.trim();
    command.toUpperCase();
    if (command == "ON") {
      digitalWrite(LED, HIGH);
      Serial.println("LED ON");
    }
    else if (command == "OFF") {
      digitalWrite(LED, LOW);
      Serial.println("LED OFF");
    }
    else {
      Serial.println("Invalid command. Use ON or OFF.");
    }
  }
}

No hay comentarios:

Publicar un comentario