libraries / VirtualWire / examples / receiver / applet / receiver.cppon 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
  17#include "WProgram.h"
  18void setup();
  19void loop();
  20void setup()
  21{
  22    Serial.begin(9600); // Debugging only
  23    Serial.println("setup");
  24
  25    // Initialise the IO and ISR
  26    vw_set_ptt_inverted(true); // Required for DR3100
  27    vw_setup(2000);      // Bits per sec
  28
  29    vw_rx_start();       // Start the receiver PLL running
  30}
  31
  32void loop()
  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        
  46        Serial.println((char*)buf);
  47                //for (i = 0; i < buflen; i++)
  48        //{
  49        //    Serial.print(buf[i], HEX);
  50        //    Serial.print(" ");
  51        //}
  52        Serial.println("");
  53        digitalWrite(13, false);
  54    }
  55}
  56
  57int main(void)
  58{
  59        init();
  60
  61        setup();
  62    
  63        for (;;)
  64                loop();
  65        
  66        return 0;
  67}
  68