[C++] Potentiometer not working

C++
VCS Version: 20180820.10.20
VEXos Version 1.02

We have potentiometer named Selector on 3-wire Port H, and VCS gives us corrupted potentiometer values (like 4294967295.4294967295 for percent value, and 0 for degree value, see screen shot below), while the V5 Brain displays them OK in 3-wire port screen (both analog value=3742 and percent value=91% are in line with expectations).

These are the commands we used:

Brain.Screen.printAt(140, 60, “analog: %f percent”, Selector.value(vex::percentUnits::pct));
Brain.Screen.printAt(140, 80, “rotation: %f degrees”,Selector.value(vex::rotationUnits::deg));

Please let us know how to fix this issue.
Potentiometer1.jpg
Potentiometer2.jpg

checking the API
http://help.vexcodingstudio.com/#cpp/namespacevex/classvex_1_1pot/value

you will see that Selector.value(vex::rotationUnits::deg) will return a 32 bit integer, so use %d not %f as format in the printAt command.

(edit: and now I see that example code there is wrong, need to get the documentation team to fix that)

Thank you for fixing the format error. But we are still unable to get anything out of the potentiometer. We switched it to PortB (to rule out port malfunction), and changed the format, but now all readings are zero (see pics), while the 3-wire port info shows 3643 (88%).

This is the code we used:

int32_t S1=0;
S1=Selector.value(vex::percentUnits::pct);
Brain.Screen.setFont(fontType::prop20);
Brain.Screen.printAt(140, 60, “analog: %d percent”, Selector.value(vex::percentUnits::pct));
Brain.Screen.printAt(140, 80, “rotation: %d degrees”,Selector.value(vex::rotationUnits::deg));
Brain.Screen.printAt(140, 100, “S1: %d percent”,S1);
Potentiometer5.jpg
Potentiometer4.jpg
Potentiometer3.jpg

Try this code, works here ok
we have some inconsistency with pot.value() calls, anything using rotationUnits returns a double, but anything returning percent returns int32_t, I need to look into that, I realize it’s confusing.


#include "robot-config.h"
          
int main() {
    int32_t S1=0;

    while(1) {
        S1=Selector.value(vex::percentUnits::pct);
        Brain.Screen.setFont(fontType::prop20);
        Brain.Screen.printAt(140, 60, "analog: %d percent", Selector.value(vex::percentUnits::pct));
        Brain.Screen.printAt(140, 85, "rotation: %.2f degrees",Selector.value(vex::rotationUnits::deg));
        Brain.Screen.printAt(140, 110, "S1: %d percent",S1);
        
        
        this_thread::sleep_for(50);
    }
}

Thank you. It works now.