 // Thresholds
 const int ACCEL_CHANGE_THRESHOLD = 500;
 const int GYRO_THRESHOLD = 300;
-const int BRIGHTNESS_THRESHOLD = 3;
+const int GYRO_MIN_SPEED_THRESHOLD = 2000;
+const int BRIGHTNESS_THRESHOLD = 10;
 const int GYRO_CALIBRATION_THRESHOLD = 1000;
 const int BRIGHTNESS_CALIBRATION_THRESHOLD = 10;
 const unsigned long TIMEOUT_USEC = 2000000L;
 const unsigned long CALIBRATE_USEC = 1000000L;
 
+// Arrays to hold measurements surrounding the reversal for debugging
+#ifdef PRINT_TRACE
+const int TRACE_SIZE = 250;
+const int TRACE_SKIP = 5;
+static int trace_count = 0;
+static int trace_skip_count = 0;
+char trace_gyroY[TRACE_SIZE];
+unsigned char trace_bright[TRACE_SIZE];
+#endif
+
 //*****************************************************
 void setup() 
 //*****************************************************
 {
   Serial.begin(9600);
-  Serial.print("OSVR_latency_hardware_firmware turnaround test v01.00.00\n");
+  Serial.print("OSVR_latency_hardware_firmware turnaround test v01.01.00\n");
   Serial.print(" Mount the photosensor rigidly on the eyepiece or screen.\n");
   Serial.print(" Rotate the inertial sensor along with the tracking hardware.\n");
-  Serial.print(" Make the app change very brightness darker in one direction and lighter in the other.\n");
+  Serial.print(" Make the app vary brightness darker in one direction and lighter in the other.\n");
   Serial.print(" Latencies reported in microseconds, 2-second timeout\n");
   Serial.print(" Hold the device still for 2 seconds.\n");
   

    tracking_axis = NULL;
    state = S_CALIBRATE;
  }
  
  switch (state) {
    // Wait for a period where there is no motion above

  // direction.  If so, then we set last_brightness_reach_end_time to
  // now.  Brightness change direction and last brightness to
  // reach the end should both be set to 0 when entering the
  // S_REVERSE_BRIGHTNESS state so that they will have to be
  // filled in by actual changes.
  static int last_brightness_change_direction = 0;
  static unsigned long int last_brightness_reach_end_time = 0;

