     
     sendSize = (sendSize + 1) % 31;
     Serial.println();
-    Blink(9,5);
-  }
+    blink_led(DPIN_RF_LED, 5);
+    log();
+  }
+  
+}
+
+//------------------------------------------------------------------------------
+void blink_led(byte pin, int delay_ms) {
+  digitalWrite(pin, HIGH);
+  delay(delay_ms);
+  digitalWrite(pin, LOW);
+}
+
+//------------------------------------------------------------------------------
+// Compares each sensor's value against its expectation, returning true if the
+// values are acceptable or false if they fall outside the expectations.
+int check_status() {
+  int status = LOW;
+  if (sensorData.ldr > sensorThresholds.light) {
+    status = HIGH;
+  }
+  if (sensorData.hall == sensorThresholds.door) {
+    status = HIGH;
+  }
+  if (sensorData.tempInsideC < sensorThresholds.minTempInsideC) {
+    status = HIGH;
+  }
+  if (sensorData.tempInsideC > sensorThresholds.maxTempInsideC) {
+    status = HIGH;
+  }
+  return status;
+}
+
+//------------------------------------------------------------------------------
+// Logs the current sensor values.
+void log() {
+  Serial.print("Light: "); 
+  Serial.print(sensorData.ldr);
+  Serial.print("\t Hall: "); 
+  Serial.print(sensorData.hall);
+  Serial.print("\t Temp: "); 
+  Serial.print(sensorData.tempInsideC);
+  Serial.print("C, "); 
+  Serial.print(sensorData.tempOutsideC);
+  Serial.println("C");
+}
+
+//------------------------------------------------------------------------------
+// Retrieves the new sensor values.
+void interogate_sensors() {
+
+  // block access to sensor data  
+  sensorData.available = false;
+  
+  // read light level
+  sensorData.ldr = map(analogRead(APIN_LDR), 0, 1023, 0, 255);
+
+  // read door status
+  sensorData.hall = digitalRead(DPIN_HALL);
+  
+  // read one-wire sensors
+  oneWireSensors.requestTemperatures();
+  sensorData.tempInsideC = oneWireSensors.getTempC(thermometerInside);
+  sensorData.tempOutsideC = oneWireSensors.getTempC(thermometerOutside);
+
+  // enable access to sensor data  
+  sensorData.available = true;
+ 
+  // update status led
+  digitalWrite(DPIN_SENSOR_LED, check_status()); 
+  
+}
+
+//------------------------------------------------------------------------------
+// Initializes the RFM12B radio.
+void setup_radio() {
+  radio.Initialize(MYID, FREQUENCY, NETWORKID, 0);
+  radio.Encrypt((byte*)KEY);
+  sprintf(buffer, "Transmitting at %d Mhz...", FREQUENCY == RF12_433MHZ ? 433 : FREQUENCY== RF12_868MHZ ? 868 : 915);
+  Serial.println(buffer);
+}
+
+//------------------------------------------------------------------------------
+// Initializes the sensors.
+void setup_sensors() {
+  
+  // initialize sensor connections
+  pinMode(APIN_LDR, INPUT);
+  pinMode(DPIN_HALL, INPUT);
+  pinMode(DPIN_SENSOR_LED, OUTPUT);
+  pinMode(DPIN_RF_LED, OUTPUT);
+  oneWireSensors.begin();
+  
+  // setup background timer to interogate sensors  
+  Timer1.initialize(1000000); // set a timer of length 100000 microseconds (or 0.1 sec - or 10Hz => the led will blink 5 times, 5 cycles of on-and-off, per second)
+  Timer1.attachInterrupt(interogate_sensors); // attach the service routine here
 }
 
 //------------------------------------------------------------------------------

        radio.SendACK();
        Serial.print(" - ACK sent.");
      }
      Blink(9,5);
    }
  }
  

  Serial.println(VERSION);
  
  // radio initialization
  setup_radio();
  
  // sensor initialization
  setup_sensors();
  
  // define default sensor thresholds
  setup_sensor_thresholds();
