Arduino - EEPROMWrite
Arduino - EEPROMWrite
Learning Examples (http://arduino.cc/en/Tutorial/HomePage) | Foundations (http://arduino.cc/en/Tutorial/Foundations) | Hacking (http://arduino.cc/en/Hacking/HomePage) | Links (http://arduino.cc/en/Tutorial/Links) Examples > EEPROM Library
EEPROM Write
The microcontroller on the Arduino board has 512 bytes of EEPROM: (http://en.wikipedia.org/wiki/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() (http://arduino.cc/en/Reference/EEPROMWrite) function. These values will stay in the EEPROM when the board is turned off and may be retrieved later by another sketch.
Hardware Required
- Arduino Board
Circuit
There is no circuit for this example.
(http://arduino.cc/en/uploads/Tutorial/Arduino_bb.png)
image developed using Fritzing (http://www.fritzing.org). For more circuit examples, see the Fritzing project page (http://fritzing.org/projects/)
Code
/ * *E E P R O MW r i t e * *S t o r e sv a l u e sr e a df r o ma n a l o gi n p u t0i n t ot h eE E P R O M . *T h e s ev a l u e sw i l ls t a yi nt h eE E P R O Mw h e nt h eb o a r di s *t u r n e do f fa n dm a yb er e t r i e v e dl a t e rb ya n o t h e rs k e t c h . * / # i n c l u d e< E E P R O M . h > / /t h ec u r r e n ta d d r e s si nt h eE E P R O M( i . e .w h i c hb y t e / /w e ' r eg o i n gt ow r i t et on e x t ) i n ta d d r=0 ; v o i ds e t u p ( ) { } v o i dl o o p ( ) { / /n e e dt od i v i d eb y4b e c a u s ea n a l o gi n p u t sr a n g ef r o m / /0t o1 0 2 3a n de a c hb y t eo ft h eE E P R O Mc a no n l yh o l da / /v a l u ef r o m0t o2 5 5 . i n tv a l=a n a l o g R e a d ( 0 )/4 ; / /w r i t et h ev a l u et ot h ea p p r o p r i a t eb y t eo ft h eE E P R O M . / /t h e s ev a l u e sw i l lr e m a i nt h e r ew h e nt h eb o a r di s / /t u r n e do f f . E E P R O M . w r i t e ( a d d r ,v a l ) ; / /a d v a n c et ot h en e x ta d d r e s s . t h e r ea r e5 1 2b y t e si n / /t h eE E P R O M ,s og ob a c kt o0w h e nw eh i t5 1 2 . a d d r=a d d r+1 ; i f( a d d r= =5 1 2 ) a d d r=0 ; } d e l a y ( 1 0 0 ) ;
See also
E E P R O M . w r i t e ( )(http://arduino.cc/en/Reference/EEPROMWrite) a n a l o g R e a d ( )(http://arduino.cc/en/Reference/AnalogRead) i f ( )(http://arduino.cc/en/Reference/If)
- EEPROM Clear example (http://arduino.cc/en/Tutorial/EEPROMClear) - EEPROM Read example (http://arduino.cc/en/Tutorial/EEPROMRead) - EEPROM library reference (http://arduino.cc/en/Reference/EEPROM)
Share
NEWSLETTER
SUBSCRIBE Enter your email to sign up 2014 Arduino Copyright Notice (http://arduino.cc/en/Main/CopyrightNotice)
Contact us (http://arduino.cc/en/Main/ContactUs)
(http://www.facebook.com/official.arduino) (http://www.flickr.com/photos/arduino_cc)