Hi Warp, this is how I do it
#define potPin 0 // the pin the pot is connected to
#define swPin 2 // pin switch is connected to
#define funcNbrFuncts 8 // the number of selectable user functions
#define HYSTERESIS 4 // value to prevent jitter at the boundry of a function
char * SelectionStrings[] = {"first", "second", "third","fourth","fifth","sixth", "seventh", "eigth" };
uint8_t ActiveSelection; // this is a global variable holding option the user has selected
void setup() {
beginSerial (9600);
}
uint8_t GetUsrOption(){
int potvalue = analogRead(potPin); // read the value from the Pot
uint8_t opt = potvalue /(1024 / funcNbrFuncts); // divide 1024 max pot value by number of options
if( opt >= funcNbrFuncts) // checks to make sure we are in range
opt = funcNbrFuncts -1;
// now remove any pot jitter on the boundry of two options
if(opt == ActiveSelection -1)
opt = (potvalue + HYSTERESIS) / (1024 / funcNbrFuncts) ; // HYSTERESIS will maintain previous option when pot is on an option boundry
else if(opt == ActiveSelection +1)
opt = (potvalue - HYSTERESIS) / (1024 / funcNbrFuncts);
return opt;
}
boolean DebounceSwitch(uint8_t pin) {
// this function returns true when a switch is pressed and stable
// for simplicity I have removed the debounce code
return digitalRead(pin);
}
void loop(){
if(DebounceSwitch(swPin)) {
ActiveSelection = GetUsrOption();
Serial.print( SelectionStrings[ActiveSelection]);
}
}
In the example here i display the string using the serial port but in the real world the selection string is written to the LCD.