const unsigned int MAX_MESSAGE_LENGTH = 12;
static char message[MAX_MESSAGE_LENGTH];
static int message_pos = 0;
void setup() {
Serial.begin(9600);
//Create a place to hold the incoming message
}
void loop() {
//Check to see if anything is available in the serial receive buffer
while (Serial.available() > 0)
{
char inByte = Serial.read();
if ( inByte != '\n' && (message_pos < MAX_MESSAGE_LENGTH - 1) )
{
message[message_pos] = inByte;
message_pos++;
}
else
{
message[message_pos] = '\0';
Serial.println(message);
message_pos = 0;
}
}
}
you could use readBytesUntil() to read a complete line terminated by a '\n'.
you could have a 2nd string and compare, strcmp(), the line just read to the 2nd string, print it if different and then strcpy() the received line to the 2nd string
Would you mind fitting your example into my code? I'm having a hard time with the 2nd string. I've been chasing my tail on this problem for a week now. This is the second sensor I've tried. The single transducer version has too big of a blind spot. This one will work great if I can get the value to print correctly