VirtualWire

I may. However, I am still trying to understand it myself...LOL For now I will just have to keep bugging everyone here. You guys have great responses and are very responsive so thats not a bad thing.. at least not for me...

Here's my loop code for sendinng out keypad presses:

void loop()
{

    // go read the keypad
  char key = keypad.getKey();                 // reading the keypad
  if(key)                                     // same as if(key != NO_KEY)- did something change?
  {
    msg[0]=key;                               // load the array with the key character
    // msg[1]=NULL;                           // Rx side seems to work without this

    digitalWrite(ledPin, true);               // Flash a light to show transmitting

    vw_send((uint8_t *)msg, strlen(msg));     // send the character out

//    Serial.println(key);                // for debugging only

    vw_wait_tx();                             // Wait until the whole message is gone

    delay (50);                               // need some delay or seem to miss key presses

    digitalWrite(ledPin, false);              // turn off the flash of LED

  }                                           // end of if(key) & transmitting a character

// do other stuff...

}                                             // end of void loop

and on the receive side

void loop(){
// look for wireless input or for unsolicited message from remote transmitter

uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;

if (vw_get_message(buf, &buflen)) // Non-blocking
{
  int i;
  digitalWrite(ledPin, LOW); // Turn on LED to show working a message
    
    switch ( buf[0] ) 
    {    // switch on the first byte in the array for now
    // caes '0':, case'1':,  2,3,4,5,6,7,8,9,A,B,C, thru case 'D':, case '*':, and case '#': sections follow for my 16 button keypad
    }
  }
}

I found this useful for understanding VW a little better. Just make sure that you match the vw_setup(2000) on the transmitter sketch and the receiver sketch if you download the code from that site because they are mismatched and will not work that way.

AWOL:

void loop()

{
 uint8_t count;
if(count==true)



It doesn't make sense to test an automatic variable like this.
If you want "count" to retain its value, make it "static".



if (true)



**Will always be true.**


]if(false)



**Will always be false.**
Awh, editted your code. By the way, I do not understand the bolded part.

Thanks

By the way, I do not understand the bolded part.

If you sort out the tags, I'll be able to see what you mean by the bolded part

AWOL:

By the way, I do not understand the bolded part.

If you sort out the tags, I'll be able to see what you mean by the bolded part

Modified !

The constant "true" will always be true, so if you say if(true), whatever follows the experession will always be executed.
If you say if (false), then whatever follows will never be executed.
That's fundamental.

Oh, so it will be a different story if I assigned a variable to be 'true' or ;false' ?

Correct ?

Oh, so it will be a different story if I assigned a variable to be 'true' or ;false' ?

Correct ?

The action, based on whether the variable contains true or false, will be the same. Which action is performed will be different IF you assign the value correctly and IF you write the test correctly.

True or false is different from HIGH or LOW right ?

i

f (variable==true)
{
 Do this
}

if (variable == false)
{
Do that
}

if (variable == HIGH)
{
Do this
}

if (variable ==LOW)
{ Do that}

Correct me if I am wrong

True or false is different from HIGH or LOW right ?

Yes.

The if(variable == true) test is silly. If variable is true, the test evaluates to true == true, which is true. So, the initial test could simply have been if(variable). That is the convention for testing boolean variables. To do something when the variable contains false, you use if(!variable) (if not true).

For non-boolean variables, the 3rd and 4th examples are correct.

what's the difference between boolean variable and non-boolean ? AND OR ?

what's the difference between boolean variable and non-boolean ?

One is a boolean variable. The other is not. It might be an int, a float, a double, a long, a char, a byte, a long long, etc.

Ok. I think is like this

If (x>y) --> this is example of boolean variable which will return either true or false.

If (variable==HIGH) --> This is non boolean variable..

Am I correct ?

Thanks

--> this is example of boolean variable which will return either true or false.

No, that is an example of two int (I'm assuming) values being compared. Comparing boolean variables using > doesn't make sense.

--> This is non boolean variable..

The statement itself does not provide enough information to answer the question. What is the type of variable? That is what determines how to write the statement. It doesn't make sense to compare a boolean variable (containing true or false) to HIGH or LOW. So, it appears that the statement does not involve a boolean variable.

Can you give me some simple example to illustrate that ?

Thanks

Can you give me some simple example to illustrate that ?

Can you learn to ask better questions? To illustrate what?

Illustrate the difference between boolean variable and non-boolean variable :smiley:

Illustrate the difference between boolean variable and non-boolean variable

boolean dense = false;
if(!dense)
{
   byte IQ = 14;
   byte min = 100;
   if(IQ > min)
   {
      // Smart enough
   }
   else
      dense = true;
}