Coding Potentiometers


Could somebody explain to me what I am doing wrong? I am trying to program a potentiometer. Any help would be appreciated. Thank you.


This is what the error says.

A potentiometer object can’t be compared to a number*. You need to use an appropriate method to extract a sensor reading from your object. What’s written is akin to saying “if Doug is greater than five…” when you really wanted to ask about how much cash Doug had in his wallet: “if Doug’s cash on hand in dollars is greater than five…” You make use of such a method on like 8, when you call Pot.value. The compiler error is telling you that you gave the > sign invalid arguments, as > only knows how to deal with numbers, not vex::pot's.

*With some extra steps, you actually could, but that gets messy. Calling the value method is easier and clearer.


Just to be clear, the 0 and then the 300 in the if and else if statements are degrees, right?

No, they’re numbers. What units they equate to will be based on what units you ask the potentiometer to report its value with. If you ask for the value in degrees, the compared numbers will be degrees. If you ask for the value in revolutions, the numbers will be in revolutions. It’s why I was careful to add the “in dollars” to my example about the contents of Doug’s wallet. If I had specified “in pesos”, the “five” would have been five pesos instead of five dollars.

1 Like

This the what is causing the error. He even reads the value once to print it.

We can also point out some “gotchas” that are obvious from reading the code. The

if( x > 0)
will always be true when x is less than 300 so the rest of the options will never happen. I think you want to be using some boolean && operators
if( x > 0 && x < 300)
This means that it has to be both greater than 0 and less than 300.


That type of program that I was using worked for ultrasonic sensors. Why is that?