         
         gLastSensorReadTimeMS = curTime;
     }
-}
-
-//------------------------------------------------------------------------------
-int measureDistanceUltrasonic( int pin )
-{
-    // Send control pulse
-    pinMode( pin, OUTPUT );
-    digitalWrite( pin, LOW );
-    delayMicroseconds( 2 );
-    digitalWrite( pin, HIGH );
-    delayMicroseconds( 5 );
-    digitalWrite( pin, LOW );
-    pinMode( pin, INPUT );
-    
-    long durationUS = pulseIn( ULTRASONIC_PIN, HIGH, MAX_ULTRASONIC_TIMEOUT_US );
-    
-    return durationUS/ULTRASONIC_US_PER_CM;
 }
 
 //------------------------------------------------------------------------------

    gPanServo.writeMicroseconds( gPanServoLimits.convertAngleToPWM( gPanServoAngle ) );
    gTiltServo.writeMicroseconds( gTiltServoLimits.convertAngleToPWM( gTiltServoAngle ) );
    
    // Periodically read from the sensors and send the readings back
    if ( curTime - gLastSensorReadTimeMS >= SENSOR_READ_INTERVAL_MS )
    {

volatile uint8_t gCurMotorWaveTick = 0;

int gLastUltrasonicReading = -1;
unsigned long gUltrasonicPulseStartTimeUS = 0;
bool gbTakingUltrasonicSensorReading = false;

// This byte determines which pins are used as digital inputs
// A bit set to 1 indicates that the pin is used as a digital input
