我试图将通过蓝牙序列发送的RFID标签号的整数值存储到一个数组中,以便读者在传递时识别标签。
while (Genotronex.available() > 2) {
int n;
for (n =0; n<10 ; n++){ // should read 10 Tags
int i;
for(i = 0 ; i < 3; i++){
BluetoothData[i] = Genotronex.read();
y[i] = BluetoothData[i] - '0'; // convert data received from BT to integer
x[n] = y[0]*100+y[1]*10+y[2]*1; // tag number of 3 digits
}
}
}
delay(100);// prepare for next data ...
if(str[0] == x[n]) //if passed tag has the same number sent from BT
{
Serial.print("Helllo World!\n");
Serial.print(n);
}
答案 0 :(得分:0)
如果您的逻辑是正确的,我发现的唯一错误是x[n]
分配在循环内。
for (n =0; n<10 ; n++){ // should read 10 Tags
for(i = 0 ; i < 3; i++){
BluetoothData[i] = Genotronex.read();
y[i] = BluetoothData[i] - '0'; // convert data received from BT to integer
}
x[n] = y[0]*100+y[1]*10+y[2]*1; // tag number of 3 digits
}//end n->for loop
试试这个。