more code...
void loop(){
//---------------------Determine Free Memory -----------------------------------
Serial.print("freeMemory()=");
Serial.println(freeMemory());
Serial.println(contrastadj);
//delay(1000);
//--------------------------------------------------------------------------------
//--------------------- Contrast set in EEPROM-----------------------------------
if(EEPROM.read(3) == 0 || EEPROM.read(3) > 80) { // contrast condition. If greater than 80 or equal to zero, then write 80 to address 3 on EEPROM
EEPROM.write(3,80);
}
//contrastadj = EEPROM.read(3); // read contrast value
analogWrite(contrastlight, contrastadj); // send EEPROM value to generate the PWM for contrast pin output
//--------------------------- Backlight set in EEPROM-------------------------------
if(EEPROM.read(2) < 40) { // check backlight condition. If not greater than or
EEPROM.write(2,40);
}
lightadj = EEPROM.read(2); // read backlight value
analogWrite(backLED, lightadj); // send EEPROM value to backlight PIN using PWM
//--------------------------- sensor Setting saved in EEPROM--------------------------
sstwarn = EEPROM.read(1); // sensor warning read from eeprom memory
//---------------------- Button for Menu -------------------------------------------
if( digitalRead(buttonPressed) == HIGH) { // if button is pressed, then do the following
if( ! alreadyPressed ) { // if alreadyPressed is not True, then do the following
alreadyPressed = true; // makes the variable alreadyPressed to True... turn on menu
lcd.clear();
}
}
if(digitalRead(cancelButtonPressed) == HIGH) {
alreadyPressed = false;
lcd.clear();
}
if (alreadyPressed == true) {
lcd.setCursor(0,0);
lcd.print("Menu Setting ");
readButtons(); //I splitted button reading and navigation in two procedures because
navigateMenus(); //in some situations I want to use the button for other purpose (eg. to change some settings)
//digitalWrite(13, HIGH); used for testing purposes only. not for production
}
else {
sensorafr(); // get sensor/afr to display on the lcd
}
if(alreadyPressed == false) {
digitalWrite(13, LOW);
}
}