Optical Sensor for distance?

Hi. My school’s other team has used all of our distance sensors, but we want to detect when our claw could close on a mobile goal. Could we use a optical sensor for this? I saw that you could use “isNearObject”, but I do not know how to set how close it is. Thank you!

Basically no, the optical sensor is not equipped to sense distance. I’d recommend a bumper switch instead.

Ok. Otherwise, would a rangefinder work?

Sensors are great for the interviewing so I would rather use some of them.

It can detect when something is close, I forget the threshold, but 2 or 3 inches perhaps.

       * @brief Check to see if an object is detected by the optical sensor.
       * @return Returns a boolean that represents whether an object has been detected.
      bool            isNearObject();

A bumper switch is a sensor. In an interview you could say having a button that makes your claw close is much more consistent than a distance sensor.

Ok. Thank you 20 char

Ok. Thank you! My question was the threshold.

do some experiments, it can be changed with this function.

       * @brief sets the value of the detection threshold
       * @param value The new detection threshold in proximity units (1 to 255).  0 means no change.
       * @return the current value of the proximity threshold
      int32_t         objectDetectThreshold( int32_t value = 0 );

but there are no units attached to that and it will change depending on how reflective the object being detected is.