EEPROM.update problem(newbie)

Hi.I am new in arduino. I am trying to program a code to allow user to change or update the value in eeprom.
I managed to run the code successfully but I seem to have a problem with the eeprom update. When I tried to read the data in the eeprom, it is still the old data,not the updated one. Can someone help me :’(

#include <EEPROM.h>

String YesNo;
float newval;
float val = 0.0001598125;
int address = 0;

void setup() {
  Serial.begin(9600);
 
  serial(); 
  Serial.println("Do you want to change the value?");//Prompt user for input
    while(Serial.available()==0){}
    YesNo=Serial.readString(); //Read user input
    if(YesNo=="yes"){
      Serial.println("Enter new value");
      while(Serial.available()==0){}
      newval=Serial.parseFloat();
      //float a= EEPROM.get(address);
      Serial.print("The value now is ");
      Serial.println(newval,10);
      EEPROM.update(address,newval);
    }
    else{
      Serial.print("The value is not changed.");
    }
}

void serial(){
  float a = EEPROM.get( address, val );  //Read value from EEPROM starting at 'address'.
  Serial.println("Welcome");
  Serial.print("Current value is ");
  Serial.println(a,10);
}
void loop() {
  // put your main code here, to run repeatedly:

}

EEPROM.update()/EEPROM.read() only deals with single bytes.

You want EEPROM.get() & EEPROM.put() to work with floats (or other large types).

Your code appears to work correctly by simply changing EEPROM.update(address,newval); to EEPROM.put(address,newval);. Just in case you are wondering, the 'put()' method does use the update() method internally.

Check the link in my sig for more info.

pYro_65:
EEPROM.update()/EEPROM.read() only deals with single bytes.

You want EEPROM.get() & EEPROM.put() to work with floats (or other large types).

Your code appears to work correctly by simply changing EEPROM.update(address,newval); to EEPROM.put(address,newval);. Just in case you are wondering, the ‘put()’ method does use the update() method internally.

Check the link in my sig for more info.

yess! thank you so much that really helps! :smiley: