int inChar;
char sData[50]; //we make a 50 byte character array to hold incoming data
String sMessage = ""; // String that will hold the complete message
boolean msg_complete = false; // Flag that when true the message is complete
int bytes_received = 0; // Character counter of received bytes
void setup() {
Serial.begin (115200);
Serial.println("MATRICULA MRDP22230");
}
void loop(){
// put your main code here, to run repeatedly:
if(Serial.available()){ // Something in the Serial input buffer?
while (Serial.available() > 0){ // While there's somethig
inChar = Serial.read(); // Read each character in the buffer
if (inChar == '\n') { // '\n' en of line "Carriage Return"
sData[bytes_received] = 0; // Null character ends the String
msg_complete = true; // Message is complete
bytes_received = 0; // re-initialice character
} else { // Message NOT complete
sData[bytes_received] = inChar; // Append character
bytes_received++; // increase char count
}
}
if (msg_complete){ // Only if message is complete
sMessage = String(sData); // Convert to String
Serial.print ("MATRICULA MRDP22230");
Serial.println (sMessage) ; // Show it
if (sMessage == "one"){ // compare to first known mssg
Serial.println("Process #1");
} else if (sMessage == "two") { // compare to second known mssg
Serial.println("Process #2");
} else if (sMessage == "three"){ // compare to third known mssg
Serial.println("Process #3");
} else {
Serial.println("Dont understand the message!");
}
msg_complete = false; // Ready to read next message
}
}
}