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@open.com.au) 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#undef int 15#undef abs 16#undef double 17#undef float 18#undef round 19void setup() 20{ 21 Serial.begin(9600); // Debugging only 22 Serial.println("setup"); 23 24 // Initialise the IO and ISR 25 vw_set_ptt_inverted(true); // Required for DR3100 26 vw_setup(2000); // Bits per sec 27 vw_rx_start(); // Start the receiver PLL running 28} 29 30void loop() 31{ 32 const char *msg = "hello"; 33 uint8_t buf[VW_MAX_MESSAGE_LEN]; 34 uint8_t buflen = VW_MAX_MESSAGE_LEN; 35 36 digitalWrite(13, true); // Flash a light to show transmitting 37 vw_send((uint8_t *)msg, strlen(msg)); 38 vw_wait_tx(); // Wait until the whole message is gone 39 Serial.println("Sent"); 40 digitalWrite(13, false); 41 42 // Wait at most 200ms for a reply 43 if (vw_wait_rx_max(200)) 44 { 45 if (vw_get_message(buf, &buflen)) // Non-blocking 46 { 47 int i; 48 49 // Message with a good checksum received, dump it. 50 Serial.print("Got: "); 51 52 for (i = 0; i < buflen; i++) 53 { 54 Serial.print(buf[i], HEX); 55 Serial.print(" "); 56 } 57 Serial.println(""); 58 } 59 } 60 else 61 Serial.println("Timout"); 62 63}