potentiometer help


#1

hey i would like to know if any of the helpful people out there knew of a way to put multiple codes on a potentiometer for autonomous mode


#2

what do u mean by that. Using multiple potentiometers ?


#3

no just one


#4

like maybe if the potentiometer is turn to a specific part it will activate one code and if its tillted another way it will activate a different code


#5

oh so autonomous selection ?


#6

I have never done a code selector with a potentiometer but if you want I could post my LCD autonomous code selector. There are also several online resources that show some potentiometer code for this. I even believe there was a forum thread a while back about this. If you do some digging you may be able to find it :slight_smile:


#7

yeah i think so


#8

I know the way you do this though is you rotate your potentiometer to a certain point and the code then reads that since it is at x point it runs y autonomous routine.


#9

Say you have CASES different programs:


int raw = SensorValue[pot]; // will get a value between 0 and 4095
float range = (float)raw/4096; // normalize to <0,1)
int selection = (int)(range * CASES); // your selection, 0 .. CASES-1
switch (selection) {
    case 0:
        // call first program
        break;
    case 1:
        // call second program
        break;
    ....]
}

I’ll let the reader figure out why the selection segments are all about the same size and why the selection stays strictly lower than CASES.


#10

can you clarify


#11

Maybe if you better clarify your question or what isn’t clear in the above snippet?


#12

in the regular auton code :


If (SensorValue[potentiometer] > 2000)
{
     //all your regular code for auton 1
}
else
{
    //all your regular code for auton 2
}

If the potentiometer is greater than a certain value (2000 in this case, which is about halfway through the pot’s range), then when auton starts, it will go to the first auton code. If it is not greater than 2000, it will run the second code.


#13

would i be able to add a greater than and less than potentiometer?


#14

Of course. But properly structured, you wouldn’t ever need to do that.


#15

If you are going to use more than two autons with asingle potentiometer I would add different color leds to verify what auton Is selected.

We typically will use two potentiometers and run four autons.


#16

If you scroll down to the “Uses” section of this article I wrote, there are some links.
https://renegaderobotics.org/vex-sensors-potentiometer/