I'm writing some code that compares information from two Arduino Unos by an Arduino Mega 2560. The problem that I'm having is that when I read the information coming in through Serial1
and Serial2
on my if
statements, I get both inputs out on my serial monitor for the Mega, but if I try to compare them after I have read them it comes out not working the way it is intended. I don't know if I might be missing some syntax on my code or if I'm doing this wrong but I would appreciate any help I can get.
byte inData;
byte inDataTwo;
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
Serial1.begin(9600);
Serial2.begin(9600);
while (!Serial)
{
; // wait for serial port to connect. Needed for native USB port only
}
}
void loop()
{
if (Serial1.available()>0 )
{
inData = Serial1.read();
Serial.print(char(inData));
}
if (Serial2.available()>0)
{
inDataTwo = Serial2.read();
Serial.print(char(inDataTwo));
}
if(inData == inDataTwo)
{
Serial.print("true");
}
else
{
Serial.print("False");
}
}`
else
– Juraj Apr 16 '19 at 15:06