VEXcode equivalent of get_proximity()

I’m using the optical sensor in VEXcode and want to be able to check the proximity value. I know I can set the threshold value with another function, but does VEXCode have an equivalent of the get_proximity()

1 Like

Try this:



VEXcode API Refrence

Visual Studio Code Vex Command Help:

I tried to find a function that gives you a range of values, but it seems that the optical sensor is only capable of basic object detection (non-continuous), if this is the problem for you, maybe consider using a Distance sensor instead.

We’ve already used that function. I’m more interested in seeing what values it uses for the proximity and what changing the threshold actually represents

You will have to use the C API, there’s no C++ member function to access proximity.

// define your global instances of motors and other devices here
vex::optical     op1(PORT10);

int main() {
    int32_t value = vexOpticalProximityGet( op1.index() );

    while(1) {
        // Allow other tasks to run

Thanks, that’s perfect! Is there a reason there’s no C++ member function?

1 Like

idk, probably just not part of the spec when we wrote the C++ class or perhaps as it is a replacement for the legacy color sensor on IQ and there was no method to read proximity on that one. There are probably quite a few C functions that do not necessarily have a C++ equivalent.


Nice! I wasn’t aware of this. I will keep this in mind :+1: