     tracking_axis = NULL;
     state = S_CALIBRATE;
   }
+  
+#ifdef PRINT_TRACE
+  if ( (state != S_CALIBRATE) && (state != S_CALM) ) {
+    if (++trace_skip_count >= TRACE_SKIP) {
+      trace_skip_count = 0;
+      if (trace_count < TRACE_SIZE) {
+        trace_gyroY[trace_count] = gyroY/100;
+        trace_bright[trace_count] = brightness/4;        
+        trace_count++;
+      }
+    }
+  } 
+#endif
   
   switch (state) {
     // Wait for a period where there is no motion above

        }
  
        if (last_gyroscope_settling_time != 0) {
          // Flush the change status so that we have to get a change in one direction
          // followed by a change in the other starting now.
          last_brightness_reach_end_time = 0;
          last_brightness_change_direction = 0;
          state = S_REVERSE_BRIGHTNESS;

    // but now have stopped.
    case S_REVERSE_DIRECTION:
      {
        // Don't say that we were moving until we get to a speed that
        // is above a larger threshold to keep us from getting lots
        // of spurious false stopping estimates.
        static bool have_moved_fast = false;
        
        // Keep track of when the gyroscope value most recently
        // dropped below threshold (was above threshold in the previous
        // time step and dropped below threshold this time).
        static int last_gyroscope_value = 0;
        if (tracking_axis != NULL) {
          if ( (*tracking_axis > GYRO_MIN_SPEED_THRESHOLD) ||
               (*tracking_axis < -GYRO_MIN_SPEED_THRESHOLD) ) {
                 have_moved_fast = true;
          }
          if ( have_moved_fast &&
               (gyro_direction(*tracking_axis) == 0) &&
               (gyro_direction(last_gyroscope_value) != 0) ) {
            last_gyroscope_settling_time = now;
          }
