I want to ask is why my "value w"
if(dataReceived[i] == test1[i])//比對回傳值
{
w++;
}
come's out the at 5 but the other's like x,y,z come's out at 3?
//apart of T
char test1[3]={'O','K','A'};
char test2[3]={'O','K','B'};
char test3[3]={'O','K','C'};
char test4[3]={'O','K','D'};
char failed[6]={'f','a','i','l','e','d'};
void getData() {
int a=5;
int i=0,x=0,y=0,z=0,f=0,w=0;
if ( radio.available() )//如果通道裡有資料
{
radio.read( &dataReceived, sizeof(dataReceived) );//讀取資料
newData = true;
for(i=0;i<a;i++)
{
if(dataReceived[i] == test1[i])//比對回傳值
{
w++;
}
if(dataReceived[i] == test2[i])
{
x++;
}
if(dataReceived[i] == test3[i])
{
y++;
}
if(dataReceived[i] == test4[i])
{
z++;
}
if(dataReceived[i] == failed[i])
{
f++;
}
}
//apart of R
char replyData1[3]= {'O','K','A'};
char replyData2[3]= {'O','K','B'};
char replyData3[3]= {'O','K','C'};
char replyData4[3]= {'O','K','D'};
char replyDatafalse[6]={'f','a','i','l','e','d'};
void send() {
if (newData == 1) {
radio.stopListening();
bool rslt;
rslt = radio.write( &replyData1, sizeof(replyData1) );
radio.startListening();
Serial.print("Reply Sent: ");
Serial.print("OK \n");
if (rslt) {
Serial.println("Received...OK\n");
}
else {
Serial.println("Received...failed\n");
}
Serial.println();
newData = 0;
}
else if(newData==2)
{
radio.stopListening();
bool rslt;
rslt = radio.write( &replyData2, sizeof(replyData2) );
radio.startListening();
Serial.print("Reply Sent: ");
Serial.print("OK \n");
if (rslt) {
Serial.println("Received...OK\n");
}
else {
Serial.println("Received...failed\n");
}
Serial.println();
newData=0;
}
else if(newData==3)
{
radio.stopListening();
bool rslt;
rslt = radio.write( &replyData3, sizeof(replyData3) );
radio.startListening();
Serial.print("Reply Sent: ");
Serial.print("OK \n");
if (rslt) {
Serial.println("Received...OK\n");
}
else {
Serial.println("Received...failed\n");
}
Serial.println();
newData=0;
}
else if(newData==4)
{
radio.stopListening();
bool rslt;
rslt = radio.write( &replyData4, sizeof(replyData4) );
radio.startListening();
Serial.print("Reply Sent: ");
Serial.print("OK \n");
if (rslt) {
Serial.println("Received...OK\n");
}
else {
Serial.println("Received...failed\n");
}
Serial.println();
newData=0;
}
else if(newData==5)
{
radio.stopListening();
bool rslt;
rslt = radio.write( &replyDatafalse, sizeof(replyDatafalse) );
radio.startListening();
Serial.print("Reply Sent: ");
Serial.print("failed \n");
if (rslt) {
Serial.println("Received...OK\n");
}
else {
Serial.println("Received...failed\n");
}
Serial.println();
newData=0;
}
}