Tutorial.EEPROMWrite History

Show minor edits - Show changes to markup

November 16, 2011, at 04:26 AM by Scott Fitzgerald -
Changed lines 27-28 from:
to:
September 28, 2010, at 01:21 PM by Tom Igoe -
Changed lines 27-60 from:
to:
September 23, 2010, at 10:46 PM by Christian Cerrito -
Changed lines 3-4 from:

EEPROM Write

to:

EEPROM Write

September 20, 2010, at 02:26 PM by Christian Cerrito -
Added lines 70-71:
September 20, 2010, at 02:26 PM by Christian Cerrito -
Changed lines 63-64 from:
to:
September 20, 2010, at 02:25 PM by Christian Cerrito -
Added lines 63-66:
September 20, 2010, at 02:16 PM by Christian Cerrito -
Changed lines 5-6 from:

Stores values read from analog input 0 into the EEPROM. These values will stay in the EEPROM when the board is turned off and may be retrieved later by another sketch.

to:

The microcontroller on the Arduino board has 512 bytes of EEPROM: memory whose values are kept when the board is turned off (like a tiny hard drive).

This example illustrates how to store values read from analog input 0 into the EEPROM using theEEPROM.write() function. These values will stay in the EEPROM when the board is turned off and may be retrieved later by another sketch.

September 20, 2010, at 02:13 PM by Christian Cerrito -
Added lines 7-12:
September 20, 2010, at 12:03 AM by Christian Cerrito -
Added lines 7-16:
September 16, 2010, at 11:11 PM by Tom Igoe -
Changed line 25 from:
  int val = analogRead(0) / 4;
to:
  int val = analogRead(A0) / 4;
September 16, 2010, at 11:11 PM by Tom Igoe -
Changed line 9 from:

[@

to:
Changed lines 40-41 from:

@]

to:
May 22, 2008, at 04:33 AM by David A. Mellis -
Changed lines 40-46 from:

@]

to:
May 22, 2008, at 04:30 AM by David A. Mellis -
Added lines 1-40:

Examples > EEPROM Library

EEPROM Write

Stores values read from analog input 0 into the EEPROM. These values will stay in the EEPROM when the board is turned off and may be retrieved later by another sketch.

Code

#include <EEPROM.h>

// the current address in the EEPROM (i.e. which byte
// we're going to write to next)
int addr = 0;

void setup()
{
}

void loop()
{
  // need to divide by 4 because analog inputs range from
  // 0 to 1023 and each byte of the EEPROM can only hold a
  // value from 0 to 255.
  int val = analogRead(0) / 4;

  // write the value to the appropriate byte of the EEPROM.
  // these values will remain there when the board is
  // turned off.
  EEPROM.write(addr, val);

  // advance to the next address.  there are 512 bytes in 
  // the EEPROM, so go back to 0 when we hit 512.
  addr = addr + 1;
  if (addr == 512)
    addr = 0;

  delay(100);
}

Share