    * Analog 5 to Arduino 5 via level shifter
    * RF Status LED attached to digital pin 9
  
-   Created 06-JAN-2015 by Jon Brule
+   Created 13-JAN-2015 by Jon Brule
 ----------------------------------------------------------------------------- */
 #include <RFM69.h>
 #include <SPI.h>

//
void loop() {
    
    // process inbound RF message
    if (receiveFromRF()) {
      sendToI2C();
      haveDataRF = false;
    }
    
    // process inbound I2C message
    if (haveDataI2C) {
      sendToRF();
      haveDataI2C = false;
    }

}


// setup the arduino board
//
void setup() {  
  Serial.begin(BAUD_RATE);
  #if SERIAL
    Serial.print("\n[OHA RF Gateway - ");
    Serial.print(VERSION);
    Serial.println("]");
  #endif
    
  setup_rf();
  setup_i2c();
}

//------------------------------------------------------------------------------
// Initializes the RF radio.
//
static void setup_rf() {
  #if SERIAL
    Serial.print("Setup radio...");
  #endif
  radio.initialize(FREQUENCY, NODEID, NETWORKID);
  radio.setHighPower();
  delay(1000);
  #if DEBUG
    Serial.println("OK");
  #endif
}

//------------------------------------------------------------------------------
// Initializes the I2C bus.
//
static void setup_i2c() {
  #if SERIAL
    Serial.print("Setup I2C...");
  #endif
  Wire.begin (I2C_ADDR);
  Wire.onReceive(receiveFromWire);
  delay(1000);
  #if DEBUG
    Serial.println("OK");
  #endif
}


