Hello awesome community, I am making this program where I'm reading a string that is sent from the
serial monitor of the Arduino IDE that then should be compared with another constant one that is stored as a constant, this is how it looks:
String StringUno, StringDos,Recibido;
void setup() {
Serial.begin(9600);
pinMode(2,OUTPUT);
StringUno = "Encender";
StringDos = "Apagar";
while(!Serial){
}
Serial.println("Comunicación Serial Exitosa");
Serial.println("Espere...");
delay(1000);
}
void loop() {
if(Serial.available()>0){
Recibido=Serial.readString();
if(Recibido == StringUno){
digitalWrite(2,HIGH);
Serial.println("String fue Encender");
Serial.print("\n");
}
if(Recibido == "Apagar"){
digitalWrite(2,LOW);
Serial.println("String fue Apagar");
Serial.print("\n");
}
}
}
I also made the code so I could read what I sent in another sketch and even it is the correct string it stills does not compare... why could it be? I tested it using a single char like 'a' and 'b' replacing the constant strings and the one readed from the serial monitor...
Any help is well recieved, thanks a lot.