HI, I'm trying to send data between two arduino but I've a little problem.
The TX/RX modules are rf 443MHz. the TX print via serial two message "X1234" and "X4321"
The rx module read the buffer but when I try to put an IF there's a problem:
#include <SoftwareSerial.h>
int car[3] ;
int carattere;
void setup(){
Serial.begin(2400);
}
void loop(){
riprova:
for (int i = 0; i < 4; i++) {
car[i] = 0;
}
if (Serial.available()){
if (char(Serial.read()) != 'X'){
goto riprova;
}
if (char(Serial.read()) != '1'){
goto riprova;
}
car[0] = Serial.read(); // Then: Get them.
car[1] = Serial.read(); // Then: Get them.
car[2] = Serial.read(); // Then: Get them.
Serial.print(char(car[0]));
Serial.print(char(car[1]));
Serial.println(char(car[2]));
}
}
If I delete the second IF it's ok but with do nothing....
Any suggestion??.
Many thanks
void loop()
{
for (int i = 0; i < 3; i++) {
car[i] = 0;
}
do {
while (Serial.available() == 0);
} while (Serial.read()) != 'X');
for (int i = 0; i < 3; ++i) {
while (Serial.available() == 0);
car[i] = Serial.read();
}
Serial.print(char(car[0]));
Serial.print(char(car[1]));
Serial.println(char(car[2]));
}