Background: I am working with Node A [Matlab+Xbee (S1)] in one side and Node B [Arduino UNO+Xbee(S1)] on another side. I am trying to send one message [message 1] from Node A to Node B, Node B would get the message1, read it and send another message [message 2] to Node A. This concept is working properly.
My requirement: In this above case I am getting message only when I am sending a message to Node B. The reason is very simple as my program is working by 'while (Serial.available())'. But I want (even when I send only one message to Node B) that Node B will not stop sending the message after once, rather it would continuously send Node A the message it sent the first time till I send another message [message 3] from Node A to Node B.
My question: Need your suggestion on how should I change the code so that it would continuously send the 1st message while it would receive value as 100. So whenever Node A again would send value 101 it would start sending continuously the 2nd message (i.e. Sending the Speed data)?
Robin2:
You need to conceptually separate receiving from sending. Read up about State Machines.
Thanks for your answer, but I need the sending function to work without getting any data in receiver once it gets a data. But your mentioned code works each time it receives data in serial port.