dhiltonp

eeprom test write

Jan 2nd, 2013
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. /*
  2.  * EEPROM Write
  3.  *
  4.  * Stores values read from analog input 0 into the EEPROM.
  5.  * These values will stay in the EEPROM when the board is
  6.  * turned off and may be retrieved later by another sketch.
  7.  */
  8.  
  9. #include <EEPROM.h>
  10.  
  11. // the current address in the EEPROM (i.e. which byte
  12. // we're going to write to next)
  13. int addr = -1;
  14.  
  15. void setup()
  16. {
  17. }
  18.  
  19. void loop()
  20. {
  21.   // need to divide by 4 because analog inputs range from
  22.   // 0 to 1023 and each byte of the EEPROM can only hold a
  23.   // value from 0 to 255.
  24.   int val = analogRead(0) / 4;
  25.   addr = addr + 1;
  26.   if (addr == 513)
  27.     return;
  28.  
  29.   // write the value to the appropriate byte of the EEPROM.
  30.   // these values will remain there when the board is
  31.   // turned off.
  32.   EEPROM.write(addr, random()%512);
  33.  
  34.   // advance to the next address.  there are 512 bytes in
  35.   // the EEPROM, so go back to 0 when we hit 512.
  36.  
  37.   delay(5);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment