I'm working on my first Arduino project (Sketch). I am using a wireless transmitter and receiver to send a message between two Arduino's. I have found plenty of examples of how to setup and send the message using VirtualWire. This all has worked out well.
I need to parse the incoming message on the receiving end so I can send a signal to the appropriate pin to go to high or low (string compare and yes I would like for it to be a string). I have figured out how to send the messages I want and I can receive the messages. Now I need to find out how to assign this char array into a sting (I think I'm using the correct terminology here). Here is what the code looks now:
void loop()
{
if (vw_get_message(message, &messageLength)) // Non-blocking
{
Serial.print("Received: ");
for (int i = 0; i < messageLength; i++)
{
Serial.write(message*);* } Serial.println(); } } Here is some really bad pseudocode for the concept I'm going for. { Serial.print("Received: "); for (int i = 0; i < messageLength; i++) { Serial.write(message*);* { completeMessage = message; Once I have the message in string format I think I can figure out the rest. Thanks.
If you'd like to create a String from a character array, try something like:
First, you still need to NULL terminate the array.
Second, don't. There is NOTHING that you can do with a String that you can't do, just as easily, with a string.
If you'd like to create a String from a character array, try something like:
First, you still need to NULL terminate the array.
Second, don't. There is NOTHING that you can do with a String that you can't do, just as easily, with a string.
BIG PLUS ONE ON BOTH COUNTS!
Lonestar, depending on what Arduino you have C++ capital-S Strings are bad or real bad news in terms of memory and excess clock cycle waste. They use extra bytes. They copy themselves even to add just 1 char then erase the old copy leaving a hole in your heap, all at cost in cycles and all just to package text in a BASIC kind of way.
Learn C char array lowercase-s strings from a C site if you can, or get a C book at a used book store or Amazon.