I'm using an Arduino Mega 2560 and writing a really simple piece of code that doesn't work.
String a, letra;
#define led 13
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
pinMode(led, OUTPUT);
}
void loop() {
while(Serial.available()) {
letra= Serial.readStringUntil('\n');
letra.trim();
Serial.println(letra);
if(letra.equals("aa\r\n")){
Serial.println("ABRE 1");
}
if(letra == "aa\r\n"){
Serial.println("ABRE 2");
}
if(letra.compareTo("aa\r\n") == 0){
Serial.println("ABRE 3");
}
}
}
It's returning what I typed, but it's not entering any of the if conditions... Can someone help me with that ?
\n
is removed from the input buffer, but excluded from the returned result, even withouttrim
.