potentiometer help


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


what do u mean by that. Using multiple potentiometers ?


no just one


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


oh so autonomous selection ?


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:


yeah i think so


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.


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
    case 1:
        // call second program

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.


can you clarify


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


in the regular auton code :

If (SensorValue[potentiometer] > 2000)
     //all your regular code for auton 1
    //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.


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


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


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.


If you scroll down to the “Uses” section of this article I wrote, there are some links.