 // gear position.  When we transition to state 2 we use this to populate
 // gear_types and gear_orientations.
 // NOTE: The photoresistor is positioned down.
-int photoresistor_totals[3][7];
-int photoresistor_counts[3][7];
+long int photoresistor_totals[3][7];
+long int photoresistor_counts[3][7];
 
 // The state of the ith gear, if we know it.  This is not its current position,
 // but rather the position corresponding to selector gear 0!  Only meaningful

        photoresistor_totals[i][selector_pos] += getRawPhotoresistor(i);
        photoresistor_counts[i][selector_pos]++;
      }

      // If we are at the end, move on to state 2.
      if (selector_pos == 6)
      {
        state = 2;
        // This fills in gear_types and gear_orientations.
        // We check that it passes each time, and that
        // we see one of each gear type.
        int failed = false;
        int types_seen = 0;
        for (int i=0; i<3; i++)
        {
          if (!computeGearPosition(i))
          {
            failed = true;
            printGearRead(i, true);
          }
          else
          {
            types_seen |= 1 << gear_types[i];
            printGearRead(i, false);
          }
        }

        if (types_seen != 7)
        {
          failed = true;
        }


        if (failed)
        {
          state = 0;
          resetLights();
        }
        else
        {
          for (int i=0; i<7; i++)
          {
            correct_positions[i] = false;
          }
        }
      }
    }
  }

  if (state == 2)
  {
    setCalibration(true);
    if (selector_pos > last_selector_pos
        || selector_pos < last_selector_pos - 1)
    {
      // They have gone backwards or too fast.
      state = 0;
      resetLights();

                    390, 280,
                    190, 70,
                    50, 24,
                    12, 5};

// above this = white; below = black (unlodged is undefined)
int photoresistor_thresholds[3] = {90, 50, 70};

// STATE OF THE WORLD

