User Manual

Sample code
8 of 13 VirtualWire
const char *msg = "hello";
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // Wait until the whole message is gone
Serial.println("Sent");
// Wait at most 400ms for a reply
if (vw_wait_rx_max(400))
{
if (vw_get_message(buf, &buflen)) // Non-blocking
{
int i;
// Message with a good checksum received, dump it.
Serial.print("Got reply: ");
for (i = 0; i < buflen; i++)
{
Serial.print(buf[i], HEX);
Serial.print(" ");
}
Serial.println("");
}
}
else
Serial.println("Timout");
}
5.4 server
Implements a simple wireless server for DR3100. Waits for a message from another
Arduino running the client code above and sends a reply.
#include <VirtualWire.h>
void setup()
{
Serial.begin(9600);// Debugging only
Serial.println("setup");
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
}
void loop()
{
const char *msg = "hello";
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
// Wait for a message
vw_wait_rx();
if (vw_get_message(buf, &buflen)) // Non-blocking
{
int i;
const char *msg = "goodbye";
// Message with a good checksum received, dump it.
Serial.print("Got: ");