Legacy Distance Sensor on V5

My students are trying to get the distance sensor working through the 3 wire ports on the v5 and are really struggling. Is there a VEX c++ sample and a wiring diagram that they could reference?

Here’s a simple program that prints the distance on the screen. VCS file attached. Connect sonar “output” to three wire port C and “input” to port D.


int main() {
    double value = 0;
    
    Brain.Screen.setFont( fontType::mono40 );
    
    while(1) {
        value = Sonar1.distance( distanceUnits::in );
        
        Brain.Screen.printAt( 10, 50, "Distance %6.1f in", value );
        
        this_thread::sleep_for( 50 );
    }
}

sonar.png
sonar.vex (2.5 KB)