#define ledBuiltIn 2
String dados = "";
struct {
int leda;
int ledb;
int ledc;
} comando_led;
void setup() {
Serial.begin(115200);
Serial.println("Ola, digite os valores dos leds (acesos ou apagados). Exemplo: 'leda1 ledb0 ledc1'");
pinMode(ledBuiltIn, OUTPUT);
}
void loop() {
if (Serial.available() > 0) {
dados = Serial.readString(); // Lê a string enviada pelo monitor serial
// Extrai os valores de leda, ledb e ledc da string
comando_led.leda = dados.substring(dados.indexOf("leda") + 4, dados.indexOf("leda") + 5).toInt();
comando_led.ledb = dados.substring(dados.indexOf("ledb") + 4, dados.indexOf("ledb") + 5).toInt();
comando_led.ledc = dados.substring(dados.indexOf("ledc") + 4, dados.indexOf("ledc") + 5).toInt();
// Controla o LED1 (pino 2) com base no valor de leda
digitalWrite(ledBuiltIn, comando_led.leda == 1 ? HIGH : LOW);
// Imprime os status dos LEDs
Serial.print("LED A: ");
Serial.println(comando_led.leda == 1 ? "Aceso" : "Apagado");
Serial.print("LED B: ");
Serial.println(comando_led.ledb == 1 ? "Aceso" : "Apagado");
Serial.print("LED C: ");
Serial.println(comando_led.ledc == 1 ? "Aceso" : "Apagado");
}
}