# 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.

2 Likes

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.

2 Likes

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