i have some problem when copy the byte array.i send "AA 12 34" through the serial port and copy it to readData[] byte array . But after i copy the data of readData[] to sendData[] , it give me an error feedback "AA 12 AA". i don't know why 34 change to AA.
GetData:AA
GetData:12
GetData:34
NewData:AA
NewData:12
NewData:AA
byte readData[2],sendData[2];
void setup() {
Serial.begin(9600);
while (!Serial) {
}
}
void loop() {
if(Serial.available()>0) {
for(int i=0;i<3;i++) {
readData[i]=Serial.read();
if ((i==0 && (readData[i]!=0xAA)) ||(i!=0 && (readData[i]==0xAA || readData[i]==0x00))) {
break;
}
delay(2);
}
for(int i=0;i<3;i++) {
Serial.print("GetData:");
Serial.println(readData[i],HEX);
}
for(int i=0;i<3;i++) {
sendData[i]=readData[i];
delay(100);
}
for(int i=0;i<3;i++) {
Serial.print("NewData:");
Serial.println(readData[i],HEX);
}
}
}