Ok, Here's what I tried.. I What you originally setup was cool, but I don't think it is going to work for what I'm trying to do.. I believe maybe an array style would be better? Perhaps you can read this and see what I'm trying to accomplish..
just to start, I would like to display Frequency result from a code I already know works.. There are at least 4 variables that need configuring however I hope to add more. I was hoping to accomplish this by stepping through each screen with the select button and using the left/right buttons to increase/decrease.. when done, I can configure either left + right to break or just tab all the way to the end with the select button to get back to the main screen.
ok, I tried your format, and I REALLY do appreciate the help.. THANK YOU!!! However, I don't think I can use that to do what I thought originally.
Here's a modded version of it (which I was hoping would work.) that's closer to what I was trying to accomplish. With this code, the buttons working were very temperamental if at all, and the LCD would display odd characters. I couldn't get "println" to work for the life of me (It acted like it wasn't printing a return character and the next line just wouldn't show on the LCD without forcefully designating where it goes.), and without some sort of delay, the entire top row of the LCD remained black after attempting to press a button. I got one of the buttons to respond to my If statements (I could see it through serial debugging), but like I said it was hit or miss if I could get it to work..
The program structure I'm looking for is kinda like this.. Only this didn't work. But I think it's probably a valid attempt for a newbie.. Hopefully I didn't kill the coding too badly. LOL
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(4,5,7,8,12,13);
// initialize variables
int n1=0;
int n2=0;
int h1=0;
int h2=0;
byte xLast;
byte yLast;
byte zLast;
void setup() {
//Setup button inputs
pinMode(A5, INPUT_PULLUP);
pinMode(A4, INPUT_PULLUP);
pinMode(A3, INPUT_PULLUP);
//Setup outputs
lcd.begin(16,2); //for display
//startup message to look all cool and stuff.
lcd.setCursor(0,0);
lcd.print(" Add lame start ");
lcd.setCursor(0,1);
lcd.print(" msg here.. ");
delay(1500);
lcd.clear();
delay(750);
}
void loop()
{
lcd.setCursor(0,0); //Display Main Program in loop
lcd.println("Freq counter. ");
lcd.setCursor(0,1);
lcd.print("(prog result)");
lcd.print(" Hz");
int key = checkKey();
//Main screen. Select setup left or right does nothing
switch (key){
case 1: // select
config0(); //Goto first config screen
break;
case 2: // left
break;
case 3: // right
break;
default: // do nothing
break;
}
}
void config0() //Start config0 (Cut1)
{
bool ready = false;
while (!ready)
{
lcd.setCursor(0,0); //Display Variable current setting
lcd.println("set CUT 1 ");
lcd.setCursor(0,1);
lcd.println(n1);
int key = checkKey();
switch (key)
{
case 1: // select
config1();
break;
case 2: // left
n1--;
break;
case 3: // right
n1++;
break;
}
}
}
void config1() //Start config1 (Cut1 Hyst)
{
bool ready = false;
while (!ready)
{
lcd.setCursor(0,0); //Display Variable current setting
lcd.println("set CUT 1 Gain");
lcd.setCursor(0,1);
lcd.println(h1);
int key = checkKey();
switch (key)
{
case 1: // select
config2();
break;
case 2: // left
h1--;
break;
case 3: // right
h1++;
break;
}
}
}
void config2() //Start config2 (Cut2)
{
bool ready = false;
while (!ready)
{
lcd.setCursor(0,0); //Display Variable current setting
lcd.println("set CUT 2 ");
lcd.setCursor(0,1);
lcd.println(n2);
int key = checkKey();
switch (key)
{
case 1: // select
config3();
break;
case 2: // left
n2--;
break;
case 3: // right
n2++;
break;
}
}
}
void config3() //Start config3 (Cut2 Hyst)
{
bool ready = false;
while (!ready)
{
lcd.setCursor(0,0); //Display Variable current setting
lcd.println("set CUT 2 Gain");
lcd.setCursor(0,1);
lcd.println(h2);
int key = checkKey();
switch (key)
{
case 1: // select
ready=true;
break;
case 2: // left
h2--;
break;
case 3: // right
h2++;
break;
}
}
}
int checkKey(){
int xState = digitalRead(A4);
int yState = digitalRead(A5);
int zState = digitalRead(A3);
if (xLast != xState){
if (xState == LOW){
return 1; //Select
}
}
if (yLast != yState){
if(yState == LOW){
return 2; //LEFT
}
}
if (zLast != zState){
if (zState == LOW){
return 3; //RIGHT
}
}
xLast=xState;
yLast=xState;
zLast=zState;
return 0;
}