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
13void setup()
14{
15 Serial.begin(9600); // Debugging only
16 Serial.println("setup");
17
18 // Initialise the IO and ISR
19 pinMode(11, INPUT_PULLUP);
20 pinMode('D12', OUTPUT);
21 vw_set_rx_pin(11);
22 vw_set_ptt_inverted(true); // Required for DR3100
23 vw_setup(2000); // Bits per sec
24
25 vw_rx_start(); // Start the receiver PLL running
26}
27
28void loop() {
29 Serial.println(digitalRead(11));
30}
31
32void oldloop()
33{
34 uint8_t buf[VW_MAX_MESSAGE_LEN];
35 uint8_t buflen = VW_MAX_MESSAGE_LEN;
36
37 if (vw_get_message(buf, &buflen)) // Non-blocking
38 {
39 int i;
40
41 digitalWrite(13, true); // Flash a light to show received good message
42 // Message with a good checksum received, dump it.
43 Serial.print("Got: ");
44
45 for (i = 0; i < buflen; i++)
46 {
47 Serial.print(buf[i], HEX);
48 Serial.print(" ");
49 }
50 Serial.println("");
51 digitalWrite(13, false);
52 }
53}