EEProm LCD Menu

Hi,
Who am I
I am a hobbyist and new to arduino. With some logical learning and browsing, i was able to understand some programming and was able to make this Menu program, which will control various settings of my project.

Why this post
I have read that we have limited eeprom write cycles,

Whats my request from community
Can somebody look at the code, as i dont want any mistake to cost me bad eeprom . (schematic also attached at end)

Big Idea
Here is the big pic. Mode button (far right) will select menu item, the knob will set new value (range 0-100) and mid button when pressed will write eeprom with new setting.

#include <EEPROM.h> // include eeprom memory for storing settings
#include <SPI.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(9);

// ********EEProm memory*************



// thermostat value in memory
int EEPthermostat;
int EEPvaluethermo;

// night light dark setting
int EEPNLdark;
int EEPvalueNLD;


// ********Caliberation button*************
int ButtonModeInput = A2; //enter exit calib mode
void ButtonModeFunc();
int ButtonMode;
int ButtonModestate;
int ButtonModecount;



// ******** set button*************
int potButtonInput = A1; //enter exit calib mode
void potButtons();
int potButton;
int potButtonstate;
int potButtoncount;


// ********Caliberation Pot *************
int SettingPotinput = A0;
void settingpotfunc();
int settingpotread;
int potvalue;



void setup() {
  Serial.begin(9600);
  pinMode(SettingPotinput, INPUT);
  pinMode(potButtonInput, INPUT);
  pinMode (ButtonModeInput, INPUT);
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);         // set the cursor to colum 0 row 0

}

void loop() {
  ButtonModeFunc();
}

//************************ Functions *****************************************
void ButtonModeFunc() {
  ButtonMode = digitalRead(ButtonModeInput);
  if (ButtonMode != ButtonModestate) {
    if (ButtonMode == HIGH) {
      ButtonModecount++;
      if (ButtonModecount >= 3) {
        ButtonModecount = 0;
      }
      Serial.print("Mode: ");
      Serial.println(ButtonModecount);
    }
    else { // do nothing
    }
  }
  ButtonModestate = ButtonMode; // save the current state as the last state for next time through the loop
  //************************ Menu Start ************************
  switch (ButtonModecount) {
    case 0:
      EEPROM.read(EEPthermostat);
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Thermostat: ");
      lcd.print(EEPvaluethermo);
      settingpotfunc(); // Function reads the setting pot value
      lcdnewvalue(); // clears bottom row and displays pot value
      potButtons();
      if (potButtoncount == 1) {
        EEPvaluethermo = potvalue;
        EEPROM.write(EEPthermostat, EEPvaluethermo);
        newvalueset(); // clears lcd and displays new value set
        potButtoncount = 0;
      }
      break;

    case 1:
      //address = EEPNLdark;
      //addressvalue = EEPvalueNLD;
      EEPROM.read(EEPNLdark);
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("LDR Dark: ");
      lcd.print(EEPvalueNLD);
      settingpotfunc(); // Function reads the setting pot value
      lcdnewvalue(); // clears bottom row and displays pot value
      potButtons();
      if (potButtoncount == 1) {
        EEPvalueNLD = potvalue;
        EEPROM.write(EEPNLdark, EEPvalueNLD);
        newvalueset(); // clears lcd and displays new value set
        potButtoncount = 0;
      }
      break;
  } // switch case end
} // void end

//******************** small assisting functions ********************//
void potButtons() {
  int potButton = digitalRead(potButtonInput);
  if (potButton != potButtonstate) {
    if (potButton == HIGH) {
      potButtoncount++;
      if (potButtoncount >= 3) {
        potButtoncount = 0;
      }
      Serial.print("Mode: ");
      Serial.println(potButtoncount);
    }
    else { // do nothing
    }
    delay(50); // to avoid button bounces
  }
  potButtonstate = potButton;
}


void settingpotfunc() {
  settingpotread = analogRead(SettingPotinput);
  potvalue = map(settingpotread, 0, 850, 0, 100);
} // void end

void lcdnewvalue() {

  lcd.setCursor(0, 1);
  lcd.print("                ");
  lcd.setCursor(0, 1);
  lcd.print("New? : ");
  lcd.print(potvalue);
  delay (50);
}// void end

void newvalueset() {
  lcd.setCursor(0, 1);
  lcd.print("                ");
  lcd.setCursor(0, 1);
  lcd.print("New Value SET! ");
  delay (500);
  lcd.setCursor(0, 1);
  lcd.print("                ");
}

// thermostat value in memory
int EEPthermostat;
//..
      EEPROM.read(EEPthermostat);

You didn't specify any address for EEPthermostat and other EEPROM locations. So it defaults to zero.

aarg:

// thermostat value in memory

int EEPthermostat;
//..
     EEPROM.read(EEPthermostat);




You didn't specify any address for EEPthermostat and other EEPROM locations. So it defaults to zero.

Also, the value read is not used.

@op, do you intend EEPthermostat to be the value returned or address to read from?

If you want to read an int into EEPthermostat use EEPROM.get() / EEPROM.put()

E.g: EEPROM.get( address_to_read, EEPthermostat );

See the link in my sig for more info (or the Arduino reference). There are examples provided with the IDE also.

aarg:

// thermostat value in memory

int EEPthermostat;
//..
      EEPROM.read(EEPthermostat);




You didn't specify any address for EEPthermostat and other EEPROM locations. So it defaults to zero.

If i am right,I planned that first time will be zero but after first run, when i set all values as per liking , the values will stay in eeprom as i wont be calibrating settings for long time. hopefully.

pYro_65:
Also, the value read is not used.

@op, do you intend EEPthermostat to be the value returned or address to read from?

If you want to read an int into EEPthermostat use EEPROM.get() / EEPROM.put()

E.g: EEPROM.get( address_to_read, EEPthermostat );

See the link in my sig for more info (or the Arduino reference). There are examples provided with the IDE also.

I think i installed the same library.

Yes, I intend to use these settings to be compared with other events and produce results, like a fan turning ON if temp reaches X degree (X degree = set in eeprom).

I have tested it on Proteus, and it does give desired results, Just wanted to make sure, if i may be overlooking something.

to gain a bit confidence, i wrote a test value in eeprom, and than uploaded new sketch that only reads previously written value. that also looked working fine

arifs:
I think i installed the same library.

Nope, you probably added a different one. My library comes with the IDE download, its built in.