libraries / VirtualWire / examples / receiver / applet / receiver.pdeon commit Added link to project report (97a3ba0)
   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@open.com.au)
   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#undef int
  13#undef abs
  14#undef double
  15#undef float
  16#undef round
  17void setup()
  18{
  19    Serial.begin(9600); // Debugging only
  20    Serial.println("setup");
  21
  22    // Initialise the IO and ISR
  23    vw_set_ptt_inverted(true); // Required for DR3100
  24    vw_setup(2000);      // Bits per sec
  25
  26    vw_rx_start();       // Start the receiver PLL running
  27}
  28
  29void loop()
  30{
  31    uint8_t buf[VW_MAX_MESSAGE_LEN];
  32    uint8_t buflen = VW_MAX_MESSAGE_LEN;
  33
  34    if (vw_get_message(buf, &buflen)) // Non-blocking
  35    {
  36        int i;
  37
  38        digitalWrite(13, true); // Flash a light to show received good message
  39        // Message with a good checksum received, dump it.
  40        Serial.print("Got: ");
  41        
  42        for (i = 0; i < buflen; i++)
  43        {
  44            Serial.print(buf[i], HEX);
  45            Serial.print(" ");
  46        }
  47        Serial.println("");
  48        digitalWrite(13, false);
  49    }
  50}