 // G - pin1
 // + - pin2
 // A - pin4
-PortI2C temp_port1 (1 /*, PortI2C::KHZ400 */); // Not sure what the commented out part is for
-DeviceI2C temperature1 (temp_port1, 0x2A);  // I2C Address of 0x2A
+
+// Secong parameter that's commented out is the rate of communication
+// Can be KHZMAX (default), KHZ400, or KHZ100
+PortI2C temp_port1 (1 /*, PortI2C::KHZ400 */);
+DeviceI2C temp_dev1 (temp_port1, 0x2A);  // I2C Address of 0x2A
+
 
 // Currently just have sensor connected to port 4
 //int DIO1 = 1 + DIO_OFFSET;
 //int DIO2 = 2 + DIO_OFFSET;
 //int DIO3 = 3 + DIO_OFFSET;
-int DIO4 = 4 + DIO_OFFSET;
+const int DIO4 = 4 + DIO_OFFSET;
 
-int temp_lo = 0;
-int temp_high = 0;
-float tempc = 0;
 
-void get_temperature() {
-  temperature1.send();
-  temperature1.write(0x00); // high byte is on register 0
-  temperature1.receive();
-  temp_high = temperature1.read(1);
-  temperature1.stop();
+// Returns the temperature of tempdev where tempdev is a DeviceI2C object
+int get_temperature(DeviceI2C tempdev) {
+  int temp_lo = 0;
+  int temp_high = 0;
+  float tempc = 0;
+
+  tempdev.send();
+  tempdev.write(0x00); // high byte is on register 0
+  tempdev.receive();
+  temp_high = tempdev.read(1);
+  tempdev.stop();
   
-  temperature1.send();
-  temperature1.write(0x10); // low byte on register 0x10
-  temperature1.receive();
-  temp_lo = temperature1.read(1);
-  temperature1.stop();
+  tempdev.send();
+  tempdev.write(0x10); // low byte on register 0x10
+  tempdev.receive();
+  temp_lo = tempdev.read(1);
+  tempdev.stop();
   
   tempc = (float)temp_lo / 256;
   tempc = tempc + temp_high;
+
+  return tempc;
 }
+
 
 void setup() {
 #ifdef DEBUG

#endif
  DEBUG_PRINT("Initializing");

  rf12_initialize(2, RF12_915MHZ, 100);

  pinMode(DIO4, INPUT);
  digitalWrite(DIO4, HIGH);  // turn on pull up
}

void loop() {
  int door_status_4 = digitalRead(DIO4);
  word payload[4] = {0,0,0,0};


ISR(WDT_vect) { Sleepy::watchdogEvent(); }


// user settings
//#define DEBUG        // Comment out to disable
const int JEELINK_ID = 1;   // Jeelink is id 1 (or 0 to broadcast)
const int NETGROUP = 100;   // Netgroup everyone is on
const int NODE_ID = 2;      // id of THIS node


// sketch constants
const int DOOR_OPEN = HIGH;    // Door open when signal is HIGH
const int DOOR_CLOSED = LOW;   // Door closed when LOW
const int DIO_OFFSET = 3;      // DIO is port num + 3


// Basic macro for debugging
// Ideally change this to a function once I figure out how to accept anything
#ifdef DEBUG
  #define DEBUG_PRINT(x) Serial.println(x)
#else
  #define DEBUG_PRINT(x)
#endif


// TEMP421 code thanks to http://ka1kjz.com (my bookmark no longer points to the source
// posting though, should still be on there somewhere
