I'm working with an rf transmitter and receiver kit to send a message between two Arduino's.
In my transmitter code I am trying to catch the whole message into a variable so I can use this outside
the for loop scope.
At this moment the message is split in an array. So for example if I send the message: "Hello World" it will send it each char at a time. Message[1] will be "H", Message[2]. will be "E" etc. (If I understand it correctly)
How can i paste these characters into one variable so I can use the whole message outside the scope?
I have been trying this for hours, but i cant find any good solution.
if (vw_get_message(message, &messageLength)) // Non-blocking
{
Serial.print("Received: ");
for (int i = 0; i < messageLength; i++)
{
Serial.write(message[i]);
}
Anonymouss:
How can i paste these characters into one variable so I can use the whole message outside the scope?
They are already in one variable, albeit an array, but it depends on what you want to do with it. For example, you can add an extra space in the array for the null-terminator, and use it with the string.h functions.
Anonymouss:
I want the message to be a String so I can use it outside the for loop scope. What is the best way to achieve this?
Not use a String and convert it to a string by adding an extra space in the message array and tacking on '\0' to the end of the message. Viola! You now have a string!
Anonymouss:
I want the message to be a String so I can use it outside the for loop scope. What is the best way to achieve this?
Not use a String and convert it to a string by adding an extra space in the message array and tacking on '\0' to the end of the message. Viola! You now have a string!
Can you give an example code? I still dont understand how I can convert the message to a string and use it outside the scope. Do you mean adding '\0' at the receiver or transmitter side of the code?