ok I've now got it so that it's working pretty well.
Here's my code:
// defining navigation button pin
#define allInOnePin A4
// Menu navigation variables
byte showMenu = 1;
boolean setButton = false;
boolean backButtonSet = false;
boolean setButtonSet = false;
boolean forwardButtonSet = false;
void buttonNavi() {
/* The screeens are navigated with back, forward and set buttons.
They act as part of a triple voltage divider with a 5K1 pulldown
resistor on analog pin A4, and one resistor each between the
buttons and Vcc (1K, 4K7 and 10K). This produces distinct
analog readings on the pin A4 for each button, which
are used to count a global-variable byte number up or down,
which is used elsewhere in the code to determine which menu
page is to be shown.
*/
int buttonState = analogRead(allInOnePin);
//Back button
if (buttonState > 250 && buttonState < 400 && !backButtonSet) {
showMenu -= 1;
backButtonSet = true;
}
// Set button
if (buttonState > 450 && buttonState < 600) {
setButton = true;
setButtonSet = true;
//Forward button
if (buttonState > 750 && buttonState < 950 && !forwardButtonSet) {
showMenu += 1;
forwardButtonSet = true;
}
/* Altogether, twelve different menu screens (hey, it's a 1.44'' display...
you can only provide so many bits of information at any one time for the driver
to notice at a glance).
Per page, two readings are displayed. Of these twelve pages, three are "settings" pages,
so we're left with nine pages of actual information, again, with two readings per page
at a time. */
if (showMenu <= 0) showMenu = 12;
if (showMenu > 12) showMenu = 1;
if (!buttonState) {
backButtonSet = false;
setButtonSet = false;
forwardButtonSet = false;
}
return showMenu;
}
void setup(){
pinMode(allInOnePin, INPUT);
}
void loop(){
buttonNavi();
}
Suggestions are still welcome...