1// client.pde 2// 3// Simple example of how to use VirtualWire to send and receive messages 4// with a DR3100 module. 5// Send a message to another arduino running the 'server' example, which 6// should send a reply, which we will check 7// 8// See VirtualWire.h for detailed API docs 9// Author: Mike McCauley (mikem@airspayce.com) 10// Copyright (C) 2008 Mike McCauley 11// $Id: client.pde,v 1.1 2008/04/20 09:24:17 mikem Exp $ 12 13#include <VirtualWire.h> 14 15void setup() 16{ 17 Serial.begin(9600); // Debugging only 18 Serial.println("setup"); 19 20 // Initialise the IO and ISR 21 vw_set_ptt_inverted(true); // Required for DR3100 22 vw_setup(2000); // Bits per sec 23 vw_rx_start(); // Start the receiver PLL running 24} 25 26void loop() 27{ 28 const char *msg = "hello"; 29 uint8_t buf[VW_MAX_MESSAGE_LEN]; 30 uint8_t buflen = VW_MAX_MESSAGE_LEN; 31 32 digitalWrite(13, true); // Flash a light to show transmitting 33 vw_send((uint8_t *)msg, strlen(msg)); 34 vw_wait_tx(); // Wait until the whole message is gone 35 Serial.println("Sent"); 36 digitalWrite(13, false); 37 38 // Wait at most 200ms for a reply 39 if (vw_wait_rx_max(200)) 40 { 41 if (vw_get_message(buf, &buflen)) // Non-blocking 42 { 43 int i; 44 45 // Message with a good checksum received, dump it. 46 Serial.print("Got: "); 47 48 for (i = 0; i < buflen; i++) 49 { 50 Serial.print(buf[i], HEX); 51 Serial.print(" "); 52 } 53 Serial.println(""); 54 } 55 } 56 else 57 Serial.println("Timout"); 58 59}