Hey,
I'm having trouble with getting the eeprom to update during the setup. I'm testing out reading and writing to the eeprom. I'm only looking to write a number at the specified address, print it out, write a new number and print that out. I only get the Serial display to spit out the same number each time. I'm sure its something Im missing very simple. Thanks here is my code
#include <EEPROM.h>
int Address_2 = 2; //variable for eeprom address 2
int Value_2 = 60; //variable to store value of 60
int Value_3 = 50; // variable to store value of 50
void setup() {
Serial.begin(9600);
int read_Value_3 = EEPROM.read(Address_2); //variable containing the value stored at address 2 of eeprom
Serial.println(read_Value_3); //print value stored in address 3 of eeprom
delay(1000);
EEPROM.write(Address_2, Value_2); //write value "50" to eeprom address 2
delay(1000);
Serial.println(read_Value_3); // print value of eeprom address 2. Should be "50".
delay(1000);
EEPROM.write(Address_2, Value_3);// write value of "60" to eeprom address 2
Serial.println(read_Value_3); // print value of eeprom address 2. Should be "60".
}
void loop() {
}
how would that look? I guess when I put that read_Value_3 variable I thought it did read from the eeprom again. I guess I dont have a good enough understanding of how it works. I've read through the arduino section on eeprom. I must be misunderstanding something. I assumed it read and printed what it returned with this statement
#include <EEPROM.h>
int Address_2 = 2; //variable for eeprom address 2
int Value_2 = 60; //variable to store value of 60
int Value_3 = 50; // variable to store value of 50
void setup() {
Serial.begin(9600);
int read_Value_3 = EEPROM.read(Address_2); //variable containing the value stored at address 2 of eeprom
Serial.println(read_Value_3); //print value stored in address 3 of eeprom
delay(1000);
EEPROM.write(Address_2, Value_2); //write value "50" to eeprom address 2
// You just wrote "60" to address 2
delay(1000);
Serial.println(read_Value_3); // print value of eeprom address 2. Should be "50".
//You just printed the same value read earlier. No change.
delay(1000);
EEPROM.write(Address_2, Value_3);// write value of "60" to eeprom address 2
// You just wrote "50" to address 2
Serial.println(read_Value_3); // print value of eeprom address 2. Should be "60".
//You just printed the same value read earlier. No change.
// next time you press reset, yes, Address_2 will have the value you just wrote to it, no change.
}
void loop() {
}
Perhaps you misunderstand the function of "=" in a C/C++ statement.
It actively transfers a value once, so this statement
int read_Value_3 = EEPROM.read(Address_2);
instructs the computer to create a new integer variable read_Value_3, read the contents of EEPROM location Address_2, and store them in the memory locations assigned to read_Value_3.