1// receiver.pde
2//
3// Simple example of how to use VirtualWire to receive messages
4// Implements a simplex (one-way) receiver with an Rx-B1 module
5//
6// See VirtualWire.h for detailed API docs
7// Author: Mike McCauley (mikem@airspayce.com)
8// Copyright (C) 2008 Mike McCauley
9// $Id: receiver.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $
10
11#include <VirtualWire.h>
12
13const int led_pin = 13;
14const int transmit_pin = 12;
15const int receive_pin = 11;
16const int transmit_en_pin = 3;
17
18void setup()
19{
20 delay(1000);
21 Serial.begin(9600); // Debugging only
22 Serial.println("setup");
23
24 // Initialise the IO and ISR
25 vw_set_tx_pin(transmit_pin);
26 vw_set_rx_pin(receive_pin);
27 vw_set_ptt_pin(transmit_en_pin);
28 vw_set_ptt_inverted(true); // Required for DR3100
29 vw_setup(2000); // Bits per sec
30
31 vw_rx_start(); // Start the receiver PLL running
32
33 pinMode(led_pin, OUTPUT);
34}
35
36void loop()
37{
38 uint8_t buf[VW_MAX_MESSAGE_LEN];
39 uint8_t buflen = VW_MAX_MESSAGE_LEN;
40
41 if (vw_get_message(buf, &buflen)) // Non-blocking
42 {
43 int i;
44
45 digitalWrite(led_pin, HIGH); // Flash a light to show received good message
46 // Message with a good checksum received, dump it.
47 Serial.print("Got: ");
48
49 for (i = 0; i < buflen; i++)
50 {
51 Serial.print(buf[i], HEX);
52 Serial.print(' ');
53 }
54 Serial.println();
55 digitalWrite(led_pin, LOW);
56 }
57}