Advertisement
RuiViana

Write_eeprom2.ino

Jul 18th, 2017
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. //Needed to access the eeprom read write functions
  2. #include <EEPROM.h>
  3.  
  4. int tempoD1 = 928;
  5. int tempoD2 = 1445;
  6. int tempoD3 = 7984;
  7.  
  8. //---------------------
  9. void EEPROMWriteInt(int address, int value)
  10. {
  11.   byte two = (value & 0xFF);
  12.   byte one = ((value >> 8) & 0xFF);
  13.   EEPROM.update(address, two);
  14.   EEPROM.update(address + 1, one);
  15. }
  16. //-----------------------
  17. long EEPROMReadInt(int address)
  18. {
  19.   int two = EEPROM.read(address);
  20.   int one = EEPROM.read(address + 1);
  21.   return ((two << 0) & 0xFF) + ((one << 8) & 0xFFFF);
  22. }
  23. //------------------------
  24. void setup()
  25. {
  26.   Serial.begin(9600);
  27. }
  28. //-------------------------
  29. void loop()
  30. {
  31.   delay(5000);
  32.   int eeAddress = 0;
  33.   EEPROMWriteInt(eeAddress, tempoD1);
  34.   eeAddress += sizeof(int);
  35.   EEPROMWriteInt(eeAddress, tempoD2);
  36.   eeAddress += sizeof(int);
  37.   EEPROMWriteInt(eeAddress, tempoD3);
  38.  
  39.  eeAddress = 0;
  40.   Serial.print(tempoD1);
  41.   Serial.print(" = ");
  42.   Serial.println(EEPROMReadInt(eeAddress));
  43.  
  44.   Serial.print(tempoD2);
  45.   Serial.print(" = ");
  46.   Serial.println(EEPROMReadInt(eeAddress += sizeof(int)));
  47.  
  48.   Serial.print(tempoD3);
  49.   Serial.print(" = ");
  50.   Serial.println(EEPROMReadInt(eeAddress += sizeof(int)));
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement