VirtualWire and Variables/Intergers

I am attempting to send a simple 2 integer transmission from one unit to another; The receiver should pick up the signal, process the 2 integers and activate a pin(7) with HIGH(1) or LOW(0) depending on the second integer.

The problem is that VirtualWire gets the data to the receiver perfectly, but i cannot "use" the information. When i Serial.println(buf*) the PROPER stuff gets printed, but when i attempt to call the buffer directly via the array index, i get 55 for the integer 7; 48 for the integer 0; and 49 for the integer 1;*
```
*// receiver.pde
//
// Simple example of how to use VirtualWire to receive messages
// Implements a simplex (one-way) receiver with an Rx-B1 module
//
// See VirtualWire.h for detailed API docs
// Author: Mike McCauley (mikem@open.com.au)
// Copyright (C) 2008 Mike McCauley
// $Id: receiver.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $

#include <VirtualWire.h>

void setup()
{
Serial.begin(9600); // Debugging only
Serial.println("setup");

// Initialise the IO and ISR
vw_set_ptt_inverted(true); // Required for DR3100
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)) // Non-blocking
{
int i;

    digitalWrite(13, true); // Flash a light to show received good message
// Message with a good checksum received, dump it.
//Serial.print("Got: ");
        int pin = 0, mode = 0;
for (i = 0; i < buflen; i++)
{
        Serial.println(buf[i]);

        if (i == 0)
          pin = (int)buf[i];
        if (i == 1)
          mode = buf[i];
    //Serial.print(buf[i]);
        //int pin = int(buf[0]), mode = buf[2];
        //if (i == 2 && buf[2] == 1)       
}

//Debugging
Serial.println("Pin:");
Serial.println(pin);
Serial.println("");
Serial.println("Mode:");
Serial.println(mode);
Serial.println("");
digitalWrite(pin, mode);

//Serial.println("");
   // Serial.println(buf[0]);
    //Serial.println("");
    digitalWrite(13, false);
}

}*
```


This first lines output CORRECTLY the information to the screen, then when i address them using the array index, its all wrong.

check out asciitable.com - what you are seeing is the ascii value of character.
For numbers, you can subtract 0x30 (decimakl 48) to convert from characters to 0-9.

Thanks for the quick response! I have gotten my project running with a work-a-round shortly after posting this; Then completely by accident i figured out that they are the ascii values; My question is; Is there a way to take the response; turn it into an INT and pass it to the digitalWrite (eg. digitalWrite(buf[0], buf[1])

Like this?

if (Serial.available() >1){
value1 = serial.Read (incomingChar) - 0x30;
value2 = serial.Read (incomingChar) - 0x30;

digitalWrite (buf[value1], buf[value2]); // assumes buf[value1] = 2 to 19 for '328 chip (0,1 being the serial lines) and buf[value2] = 0 or 1
}

Hello moneyblind,

instead of fixing the received data, why don't you fix the data that you are sending? Your sending side screenshot shows that you transmit a string of "71". If you looked at the raw data in memory, you'd see exactly the ASCII values that you receive. Define an array of uint8_t and length 2. Then set the index 0 to 7 (not '7') and index 1 to 1 (again, not '1'). Then you should receive the proper values on the receiving side, no correction necessary.

Christoph