   }
   return 0;
 }
-
+// End of SRF command functions
 
 void setup() {
-  // initialise serial:
+  // initialise serial interface for debugging/SRF communication:
   Serial.begin(115200);
+
   // Get device ID
   readJumpers();
 
   // Initialise the LLAPSerial library
   LLAP.init( nodeId );
+
+  // Set unused digital pins to input and turn on pull-up resistor
   analogReference(DEFAULT);
-
-  // Set unused digital pins to input and turn on pull-up resistor
   for(int i = 0; i< PIN_COUNT; i++ ) {
     pinMode(inPin[i], INPUT);
     digitalWrite(inPin[i], HIGH);

  pinMode(SENSOR_PIN, INPUT);

  // Setup the SRF pins
  pinMode(SRF_RADIO_ENABLE, OUTPUT);    // initialize pin 8 to control the radio
  digitalWrite(SRF_RADIO_ENABLE, HIGH); // select the radio
  pinMode(SRF_SLEEP, OUTPUT);
  digitalWrite( SRF_SLEEP, LOW );

  sensors.begin();
  tempSensorFound = false;
  if (sensors.getAddress(temperatureSensor, 0)) {
    // set the resolution to 9 bit (Each Dallas/Maxim device is capable of several different resolutions)
    sensors.setResolution(temperatureSensor, 9);
    tempSensorFound = true;
  }

  batteryCountDown = BATTERY_READ_INTERVAL;
  // Wait for it to be initialised
  delay(200);

  // Send START message if successful or ERROR if not able to set SleepMode 3.
  // set up sleep mode 3 (low = awake)
  uint8_t val;
  while ((val = setSRFSleep(TWENTYSEC)) != 5) {

  }
}

// Start of Ultrasonic sensor code
boolean getRange( int *outRawDistance, int *outDistance, float *outTemperature ) {

  // Get the range in cm. Need to enable sensor first then wait briefly for it to power up
  // Also request temperture sensor, if previously detected, to take a reading.
  // Disable sensor after use.
  // Returns compensated, uncompensated and temperature values as reference params
  // boolean true returned form function for valid reading. false for <23cm or out of range
  // Calling function can still do checks to determine whether to use reading or not.

  int16_t pulse;  // number of pulses from sensor
  int i=0;
  // These values are for calculating a mathematical median for a number of samples as
