Temperature EEPROM saver

I am making a temperature sensor. I want to make it so that I can save the temperature using EEPROM. I want to be able to save it and then scroll through the saved temps. I thought I might be able to assign a temperature to a number than scroll through it using a potentiometer. I want to know if this is possible and how I might be able to do this Please ignore spelling mistakes

#include <ezButton.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#include <LCD_I2C.h>
#include <EEPROM.h>

bool useCelcius = true;

DHT dht(11, DHT11);

LCD_I2C lcd(0x27, 16, 2); // Default address of most PCF8574 modules, change according

ezButton button(4); // create ezButton object that attach to pin 4;
int button2 = 7;
int button3 = 6;


void setup() {
  EEPROM.write(0, 0);
  pinMode(button2, INPUT_PULLUP);
  Serial.begin(9600);
  button.setDebounceTime(50); // set debounce time to 50 milliseconds
  lcd.begin(); // If you are using more I2C devices using the Wire library use lcd.begin(false)
  // this stop the library(LCD_I2C) from calling Wire.begin()
  lcd.backlight();
  dht.begin();
}



void tempature() {
  int celcius = dht.readTemperature();
  int farenheit = dht.readTemperature(true);
  int humidity = dht.readHumidity();
  int heat = dht.computeHeatIndex(celcius, humidity, false);
  button.loop(); // MUST call the loop() function first

  if (button.isPressed()) {
    // change state of switch
    useCelcius = !useCelcius;
  }

  if (!useCelcius) {
    lcd.setCursor(0, 0);
    lcd.print("   Heat Index   ");
    lcd.setCursor(7, 1); //
    lcd.print(heat); //
    lcd.print("C");
    lcd.print("       ");
  }
  else {
    lcd.setCursor(0, 0);
    lcd.print("     Celsius    ");
    lcd.setCursor(7, 1); //
    lcd.print(celcius); //
    lcd.print("C");
    lcd.print("       ");
  }
}
void saving() {
  int celcius = dht.readTemperature();
  int humidity = dht.readHumidity();
  int heat = dht.computeHeatIndex(celcius, humidity, false);

  int one
  int two
  int three
  int four
  int five

    celcius = EEPROM.read(0);
    Serial.println(celcius);

      lcd.setCursor(0, 0);
      lcd.print("     SAVING    ");
      lcd.setCursor(0, 1);
      lcd.print("                 ");
  }

void loop() {
  if (digitalRead(button2) == HIGH){
   tempature();
  }
    else {
      saving();
      delay(2000);}
      
  }

I don't know what good assigning a number would do, just map the pot (use a linear pot) values to some arbitrary mapping. It will likely need to be a fairly small number as a regular pot only moves a small amount. BUT get one of those multi turn pots and you will have many more choices. I just did an Amazon search on 'multi turn precision pot' and quite a few turned up.

You declare celcius (celsius) and assign it a temperature value then a few lines later you overwrite that value by EEPROM.read(0);

https://docs.arduino.cc/learn/built-in-libraries/eeprom/

This:

int one
int two
int three
int four
int five

won't fly.

A quadrature encoder, with accompanying code, might suit this better.

You already have an "index" for your data, the EEPROM address. I would suggest you use an encoder to scroll, they don't "bounce" and you can go around as many times as you want.

Consider if you are going to save a "time" with your data. You could save the millis() or perhaps seconds (or minutes) since rebooting (or resetting a variable by another button).

" ; " missing in all lines.

Be aware that EEPROM.write() only writes a single byte and EEPROM.read() only reads a single byte. You're using integers (2 or 4 bytes depending on the board that you're using) for the temperatures so your attempt will fail. Use EEPROM.put() to write and EEPROM.get() to read; see the reference.

You will need to keep track of where you are writing; use an integer as an index variable so you know where to write the next time (increment it after writing); call it e.g. writeIndex.

You will also need a similar variabke for the reading; call it readIndex.

The locations in the EEPROM need to be incremented by the size of the temperature variable. So you can not write to location 0, location 1 etc but you write to writeIndex * sizeof(celsius) and you read from readIndex * sizeof(celsius).

If you also want to store the humidity, the locations will be writeIndex * (sizeof(celsius) + sizeof(humidity)); similar for the read.

@jacob4838034
see if this code meets your needs.
But note that a common potentiometer will be very difficult to hit the exact point you want to list.
The ideal would be to use a multi-turn potentiometer as recommended by @sonofcy.
This code is simulated at:

#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#include <LCD_I2C.h>
#include <EEPROM.h>
int EEPROM_lgt = 8;
int EEPROM_add = 0;
int EEPROM_lst = 0;
long EEPROM_ok = 0;

bool useCelsius = true;
DHT dht(11, DHT11);
LCD_I2C lcd(0x27, 16, 2); // Default address of most PCF8574 modules, change according
#define button4 4
#define pot A0
int myPos = 0;
int myPosOld = 0;
int myPosCalc = 0;
float celsius = 0;
float fahrenheit = 0;
float humidity = 0;
float saved_Celsius = 0;
float saved_Frenheit = 0;
//-------------------------------------------------------------------
void setup() {
  Serial.begin(9600);
  pinMode(button4, INPUT_PULLUP);
  lcd.begin(); // If you are using more I2C devices using the Wire library use lcd.begin(false)
  lcd.backlight();
  dht.begin();
  celsius = dht.readTemperature();
  fahrenheit = dht.readTemperature(true);
  humidity = dht.readHumidity();
  if (EEPROM.get(0x03FC, EEPROM_ok) == 0x0A0A0A0A) {
    EEPROM.get(0x03F8, EEPROM_lst);
    Serial.println(EEPROM_ok, HEX);
    Serial.println(EEPROM_lst, HEX);
  }
  else {
    EEPROM.put(0x03FC, 0x0A0A0A0A);
    EEPROM.put(0x03F8, EEPROM_lst);
  }
  saving();
  lcd.setCursor(0, 0);
  lcd.print("     Celsius    ");
  lcd.setCursor(7, 1); //
  lcd.print(celsius); //
  lcd.print("C");
  lcd.print("       ");
}
//-------------------------------------------------------------------
void temperature() {
  celsius = dht.readTemperature();
  fahrenheit = dht.readTemperature(true);
  humidity = dht.readHumidity();
  useCelsius = !useCelsius;
  if (!useCelsius) {
    saving();
    lcd.setCursor(0, 0);
    lcd.print("   Fahrenheit   ");
    lcd.setCursor(7, 1); //
    lcd.print(fahrenheit); //
    lcd.print("F");
    lcd.print("       ");
  }
  else {
    saving();
    lcd.setCursor(0, 0);
    lcd.print("     Celsius    ");
    lcd.setCursor(7, 1); //
    lcd.print(celsius); //
    lcd.print("C");
    lcd.print("       ");
  }
}
//-------------------------------------------------------------------
void saving() {
  lcd.setCursor(0, 0);
  lcd.print("     SAVING    ");
  lcd.setCursor(0, 1);
  lcd.print("                 ");
  EEPROM.put(EEPROM_lst, celsius);
  EEPROM_lst += 4;
  EEPROM.put(EEPROM_lst, fahrenheit);
  EEPROM_lst += 4;
  if (EEPROM_lst >= 0x03F8) {
    EEPROM_lst >= 0x0;
  }
  EEPROM.put(0x03F8, EEPROM_lst);
  //Serial.println(EEPROM_lst, HEX);
  delay(100);
}
//-------------------------------------------------------------------
void loop() {
  if (digitalRead(button4) == LOW) {
    delay(30);
    if (digitalRead(button4) == LOW) {
      temperature();
    }
  }
  while (digitalRead(button4) == LOW) {}
  myPos = analogRead(pot);
  if (myPos != myPosOld) {
    myPosOld = myPos;
    myPosCalc = map(myPos, 0, 1024, 0, 256) * 4;
    EEPROM.get(myPosCalc, saved_Celsius);
    if (!isnan(saved_Celsius)) {
      Serial.print("EEPROM  ");
      Serial.print(myPosCalc);
      Serial.print(" = ");
      Serial.print(saved_Celsius);
      Serial.print(" C   ");
    }
    EEPROM.get(myPosCalc + 4, saved_Frenheit);
    if (!isnan(saved_Frenheit)) {
      Serial.print("EEPROM  ");
      Serial.print(myPosCalc + 4);
      Serial.print(" = ");
      Serial.print(saved_Frenheit);
      Serial.println( "F" );
    }
  }
}

This code might help:

/***

    eeprom_get example.

    This shows how to use the EEPROM.get() method.
    To pre-set the EEPROM data, run the example sketch eeprom_put.
    This sketch will run without it, however, the values shown
    will be shown from what ever is already on the EEPROM.
    This may cause the serial object to print out a large string
    of garbage if there is no null character inside one of the strings
    loaded.

    Written by Christopher Andrews 2015
    Released under MIT licence.

***/

#include <EEPROM.h>

void setup() {

  float f = 0.00f;   //Variable to store data read from EEPROM.
  int eeAddress = 0; //EEPROM address to start reading from
  byte value;

  Serial.begin(9600);

  while (!Serial) {

    ; // wait for serial port to connect. Needed for native USB port only

  }

  delay(10000);

// read first few bytes to see if the "default" value is 255

  Serial.print("Read first 3 bytes: ");
  value = EEPROM.read(0);
  Serial.print(value);  Serial.print("    ");

  value = EEPROM.read(1);
  Serial.print(value);  Serial.print("    ");

  value = EEPROM.read(2);
  Serial.println(value);

 
  Serial.print("Read float from EEPROM: ");

  //Get the float data from the EEPROM at position 'eeAddress'

  EEPROM.get(eeAddress, f);

  Serial.println(f, 3);    //This may print 'ovf, nan' if the data inside the EEPROM is not a valid float.

  /**
    As get also returns a reference to 'f', you can use it inline.
    E.g: Serial.print( EEPROM.get( eeAddress, f ) );
    Get can be used with custom structures too.
    I have separated this into an extra function.

  **/

  secondTest(); //Run the next test.
}

struct MyObject {

  float field1;

  byte field2;

  char name[10];
};

void secondTest() {

  int eeAddress = sizeof(float); //Move address to the next byte after float 'f'.

  MyObject customVar; //Variable to store custom object read from EEPROM.

  EEPROM.get(eeAddress, customVar);

  Serial.println("Read custom object from EEPROM: ");

  Serial.println(customVar.field1);

  Serial.println(customVar.field2);

  Serial.println(customVar.name);
}

void loop() {

  /* Empty loop */
}