Potentiometer code help

Potentiometer help
i have never use a potentiometer so i made this off the top of my head for the Change Up season. Theoritically, would this code work?

no. You want to rotate at a speed or power, not for a specific distance.


What it seems you are trying to do is measure the distance to the spot you want in degrees and then just rotating that many degrees. I see what you are thinking, but this is not how potentiometers are generally used. (also the potentiometer doesn’t by default measure in degrees)

What is normally done is that the brain multitask to repeatedly find the current potentiometer position and compare it to the target pot position to determine how much power the motor should be given to reach the target and not overshoot in that instant.

Also, I’m not confident that your code is going to do what you want it to. I don’t know what triggers Up to be true, but it is only then and when count is even (make sure that checks for button releases, not intervals thorough code in which the button is being pressed) that the lift will move regardless of what’s outside this function.


Ohh yeah now that you mention it, it does make sense. Thanks for the reply. Btw Up is what i defined as the up button on the controller. In order to track the potentiometer value continously, i need to use while loop instead of if right?

Correct. I think what you are looking for is something like this:

while(!interruptButton){ // something like !Up.pressing();
    error = targetpot - currentpot;
    lift.spin(forward, error*constant, pct);