Go Down

Topic: input and if (Read 1 time) previous topic - next topic


Aug 12, 2009, 12:56 pm Last Edit: Aug 12, 2009, 12:57 pm by HULK Reason: 1
Could anybody give me a hint on how to solve this.
Below you can find the virtual vire code for RX.
I am reciving the message "hello 6" and trying to do something when buf[6] is equal to 6.
Could it be that i am not converting the value so it can be compared?
When i serial print the buf[6] it prints 6 but when i compare it in the "if" code it does not see it as a 6.

Code: [Select]

#include <VirtualWire.h>

#undef int
#undef abs
#undef double
#undef float
#undef round

void setup()
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver PLL running

void loop()
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;

 if (vw_get_message(buf, &buflen)) {
  int i;
  Serial.print("Got: ");
   for (i = 0; i < buflen; i++) {
    Serial.print(buf[i], BYTE);
    Serial.print(" ");
   if (buf[6] == 6) { Serial.println("ON"); }


Aug 12, 2009, 01:18 pm Last Edit: Aug 12, 2009, 01:18 pm by HULK Reason: 1
Simple solution, found it on my own.
The solution is to write:

Code: [Select]
if (buf[6] == '6') {
instead of

Code: [Select]
if (buf[6] == 6) {

I do not technically why but it works.


Aug 12, 2009, 04:22 pm Last Edit: Aug 12, 2009, 04:23 pm by Spinlock Reason: 1
Code: [Select]
buf[6] == 6
is checking to see if the character has ASCII value 6.

Code: [Select]
buf[6] == '6'
is checking if the character is the character 6.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131