Code annotated with comments to explain what it seems to do
void displayMenu() { //it looks like it displays a menu on an LCD and allows the user to select the required action
int selected = 3; //start with option 3 selected
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Turn the knob to"); //prompt the user
lcd.setCursor(0,1);
lcd.print("select an option");
// display options
while (!buttonR.isPressed()) { //while the button is not pressed
selected += readEncoder(); //read the encoder and update the selected variable
if (selected<0) selected=3; //deal with wrap around if the selected variable
if (selected>3) selected=0;
if (moved) { //presumably moved is updated to true if readEncoder detects movement
lcd.clear(); //if the encoder has moved perform these actions
lcd.setCursor(0,0);
switch(selected) { //display messages depending on the value of the selected variable
case 0: //if it's 0
lcd.print("Change Units ");
break;
case 1: //if it's 1
lcd.print("Backlight On/Off");
break;
case 2: //if it's 2
lcd.print("Logging On/Off ");
break;
case 3: //if it's 3
lcd.print("Exit Settings ");
break;
}
}
} //end of the while detecting button press
// when button is pressed...
lcd.clear();
switch(selected) { //now run functions based on the value of selected
case 0:
settingsChangeUnits();
break;
case 1:
settingsChangeBacklight();
break;
case 2:
settingsChangeLogging(); //there would normally be a break after each case
}
} //end of the function. No value is returned but global variables
//may have been altered in the functions but selected is local