Hardware Reference
In-Depth Information
The write() function writes a byte contained in data to a specii c address
adr . This function does not return any values.
EEPROM.write(adr, data);
The Arduino compiler automatically sets the correct start memory location. It
doesn't matter if you use an Uno, Mega2560, or Mini; the compiler “translates”
the correct address. Reading at memory location 0 read from the i rst byte of
EEPROM.
Consider the following program:
byte value;
void setup()
{
// initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
// wait for serial port to connect. Needed for Leonardo only
}
value = EEPROM.read(0);
Serial.print("Value at position 0:");
Serial.print(value, DEC);
Serial.println();
}
void loop(){}
In this program, the Arduino reads the i rst byte of EEPROM memory and
displays it over the serial interface. Yes, it is that simple. Writing a byte into
memory is just as straightforward:
void setup()
{
EEPROM.write(0, value);
}
void loop() {}
Writing a byte erases the byte in memory before rewriting, and this takes some
time. Each write takes approximately 3.3 ms for each byte. Writing the entire
contents of a 512-byte EEPROM device takes a little more than 1 1/2 seconds.
Reading and Writing Bits
Bits are used when using true/false values. In some applications there will be
relatively few (or sometimes none at all), and in others, you will use boolean
variables extensively. An Arduino cannot write individual bits to EEPROM; to
store bits, they must i rst be stored in a byte. There are two possibilities.
 
Search WWH ::




Custom Search