How to use "vw_get_message"?

Hi. I want to know with "vw_get_message", is there a way to use it for an if statement? Basically, if the character is "1", then this Arduino device is supposed to activate a servo, or more correctly, launch the loop that handles the servo. If the character is "0", then nothing happens.

Examples given always show it for a transmitted string, but is there a quicker way for receiving a single character?

Thank you!

Send and receive string of length 1, containing 1 character. Don't forget that a string of length 1 has a zero terminator, so occupies two bytes.

Thank you. The two possible values I’m having received are “0” and “1”, so do I have to refer to

uint8_t buf[1]
//....skipped stuff in between for this example
if (vw_get_message(buf, 0) == '1'

To say “if the first byte is equal to ‘1’”…I say first byte because you told me the second one is always zero if it’s a single character being sent.

You MUST declare buf to be of length > 1, to accommodate the zero terminator, e.g.

uint8_t buf[2];

Then the receive operation and comparison will be something like

uint8_t len=1;
if (vw_get_message(buf,len)) {
   if (buf[0] == '1') { do something;}
}

Something like

uint8_t buf[2]; //set to minimum length, to accomadate "terminator"

...... //stuff skipped

//Servo runs, only if "1" is received
if (vw_get_message(buf,len)) {
   if (buf[0] == '1')
   {
    for(pos = 0; pos < 90; pos += 1)  // goes from 0 degrees to 90 degrees
    {                                  // in steps of 1 degree
      thisservo.write(pos);              // tell servo to go to position in variable 'pos'
      delay(delayer);                       // waits for the servo to reach the position
    }
    for(pos = 90; pos>=1; pos-=1)     // goes from 90 degrees to 0 degrees
    {                               
      thisservo.write(pos);              // tell servo to go to position in variable 'pos'
      delay(delayer);                       // waits for the servo to reach the position
    }
   }

Also, do I have to set length at the “transmitting” end? (this is just from the “receiving”)

do I have to set length at the “transmitting” end?

Of course you must.

Ok. And another thing....for

"if (vw_get_message(buf,len))"

How do you declare the "length" of an incoming message, especially if it's theoretically variable (since the messages I expect to use are all "2" in length, that is the actual "1" or "0" and the "terminator", can I just replace the "len" with "2"?)

Your most reliable source of information is the documentation for VirtualWire.