Well I don't know if thats what you wanted, but thats the main file of the script:
#include <Boards.h>
#include <Firmata.h>
/*Small display manager for 16, 2 LCD display. Able to use and display multiple layers per page. Easy t edit and add pages
* written by Johannes Zeiser 25.01.2016
*/
#include <EEPROM.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
boolean firstRun = true;
const int key0=40;
const int key1=41;
const int key2=42;
const int key3=43;
const int led0=8;
const int pager=7;
const int lcdled=9;
int temp=0;
int keyCount;
int pdel=0;
boolean writeStorg = false;
int page=0; //current page menu is on
int lastpage=0; //page used in last cycle
const int maxpage=4; //tells the max page count. Used to specify the number of pages. Don't use minpage to increase page count.
const int minpage=0; //should almost always stay at 0
int pagelay=0;//tells which layer of the page is currently used. 0 is the normal cycling menu, 1 is for editing values.
int lstpagelay=0;
const int minPagelay=0;
const int maxPagelay=1;
int count=0;
int keyCountArray[4];
int keyStatArray[4];
boolean buzzerstat = false;
int led0stat = 0;
int lcdledstat = 10;
boolean intRead = false;
char page4[6] = "hello";
int page4num[6];
int iCursor = 0;
boolean curs = false;
void setup() {
lcd.begin(16, 2);
pinMode(key0, INPUT);
pinMode(key1, INPUT);
pinMode(key2, INPUT);
pinMode(key3, INPUT);
pinMode(led0, OUTPUT);
pinMode(pager, OUTPUT);
pinMode(lcdled, OUTPUT);
}
void loop() {
count = keyCountArray[2];
Serial.begin(9600);
Serial.println(count);
lcd.setCursor(11, 1);
lcd.print(count);
//storage();
//Input processing
pagelay = button(key3, maxPagelay+1, minPagelay-1, pagelay, 1, false);
if(pagelay > maxPagelay){
pagelay = minPagelay;
}
if(pagelay < minPagelay){
pagelay = minPagelay;
}
if(pagelay == 0){ //enter page cycler
//key+
page = button(key2, maxpage+1, minpage-1, page, 1, true);
//key-
page = button(key1, maxpage+1, minpage-1, page, -1, true);
if(page > maxpage){ //infinite page run
page = minpage;
}
if (page < minpage){
page = maxpage;
}//infinite page run end
}// exit page cycler
if(page != lastpage){
lcd.clear();
firstRun = true;
}
//page1 funktion
if(page == 0){
lcd.setCursor(0, 0);
lcd.print("LED ON/OFF");
if(pagelay == 1){
//KEY-
led0stat = button(key1, 10, 0, led0stat, -1, true);
//KEY+
led0stat = button(key2, 10, 0, led0stat, 1, true);
}
//led0stat output streamer
lcd.setCursor(0, 1);
lcd.print(led0stat);
if(led0stat < 10){
lcd.setCursor(1, 1);
lcd.print(" ");
}
}
//page2 funktion
if(page == 1){
lcd.setCursor(0, 0);
lcd.print("page 2");
lcd.setCursor(0, 1);
lcd.print("Yeeees!!");
}
//page3 funktion
if(page == 2){
lcd.setCursor(0, 0);
lcd.print("Buzzer ON/OFF");
lcd.setCursor(0, 1);
if(buzzerstat == true){
lcd.print("ON ");
}
else{
lcd.print("OFF");
}
if(pagelay == 1){
buzzerstat = button(key2, 1, 0, buzzerstat, 1, true);
buzzerstat = button(key1, 1, 0, buzzerstat, -1, true);
}
}
if(page == 3){
if(page != lastpage){
lcd.setCursor(0, 0);
lcd.print("LCD brightness");
}
if(pagelay == 1){
//KEY-
lcdledstat = button(key2, 10, 0, lcdledstat, 1, true);
lcdledstat = button(key1, 10, 0, lcdledstat, -1, true);
}
lcd.setCursor(0, 1);
lcd.print(lcdledstat);
if(lcdledstat < 10){
lcd.setCursor(1, 1);
lcd.print(" ");
}
}
if(page == 4){
if(page != lastpage || firstRun == true){
lcd.setCursor(0, 0);
lcd.print("Text input");
lcd.setCursor(0, 1);
lcd.print(page4);
}
if(pagelay == 1){
if(curs == false){
lcd.setCursor(8, 1);
lcd.cursor();
curs = true;
}
}
else{
lcd.noCursor();
curs = false;
}
}
//generall output stream
analogWrite(led0, led0stat*25.5);
analogWrite(lcdled, lcdledstat*25.5);
if(buzzerstat == true){
digitalWrite(pager, HIGH);
}
else{
digitalWrite(pager, LOW);
}
if(lstpagelay != pagelay || firstRun == true){
if(pagelay == 0){
lcd.setCursor(15, 1);
lcd.print(" ");
lcd.setCursor(15, 0);
lcd.print("*");
}
if(pagelay == 1){
lcd.setCursor(15, 0);
lcd.print(" ");
lcd.setCursor(15, 1);
lcd.print("*");
}
}
lastpage=page;
lstpagelay=pagelay;
if(firstRun == true){
firstRun = false;
}
}
and thats the button function, the previous code is from
int button(int key, int maxValue, int minValue, int currentValue, int change, boolean longPress){
boolean keyStat = 0; //setting keyStat to 0 to prevent errors
int countNumber = key - 40;//calculating the bank of the array the keyCounter is contained in
boolean keyStat1 = 0;
const int changeSpeed = 50;
const int enterSpeed = 60;
keyCount = keyCountArray[countNumber];
keyStat1 = keyStatArray[countNumber];
keyStat = digitalRead(key);
if(longPress == 1){
if(keyStat == 1){//LONG PRESS AKTION BEGINN
keyCount = keyCount + 1; //KEY CYCLE CONTINUS COUNTER
}
else{
keyCount = 0;
}
if(keyCount > enterSpeed){// basically how long it takes to initiate long button press aktion
if(change>0){
if(currentValue+1 <= maxValue){
currentValue = currentValue + change; //changing value on long button holds per run
}
}
if(change<0){
if(currentValue-1 >= minValue){
currentValue = currentValue + change;
}
}
keyCount = keyCount - changeSpeed; //reseting the count to a certain level to get the value to change slower "benni"
}
}//LONG PRESS AKTION END
if(keyStat == 1 && keyStat1 == 0){//SINGLE PRESS AKTION
if(change>0){
if(currentValue+1 <= maxValue){
currentValue = currentValue + change;
}
}
else{
if(currentValue-1 >= minValue){
currentValue = currentValue + change;
}
}
}
keyCountArray[countNumber] = keyCount; //putting the count out to the array
keyStatArray[countNumber] = keyStat;
return currentValue;
}