Advertisement
pleasedontcode

**EEPROM Access** rev_01

Nov 7th, 2024
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: **EEPROM Access**
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-11-07 08:37:48
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* interfacing eeprom and intigrate with builtin one */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /* START CODE */
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <EEPROM.h>
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31.  
  32. /****** GLOBAL VARIABLES *****/
  33. int addr = 0; // Current address in the EEPROM for writing
  34. int address = 0; // Current address in the EEPROM for reading
  35. byte value; // Variable to store the read value
  36.  
  37. void setup(void)
  38. {
  39.     // Initialize serial communication for reading values
  40.     Serial.begin(9600);
  41.     while (!Serial) {
  42.         ; // wait for serial port to connect. Needed for native USB port only
  43.     }
  44. }
  45.  
  46. void loop(void)
  47. {
  48.     // Write to EEPROM
  49.     int val = analogRead(0) / 4; // Read analog input and scale
  50.     EEPROM.write(addr, val); // Write value to EEPROM
  51.     addr++; // Advance to the next address
  52.     if (addr == EEPROM.length()) {
  53.         addr = 0; // Wrap around if at the end
  54.     }
  55.  
  56.     // Read from EEPROM
  57.     value = EEPROM.read(address); // Read a byte from EEPROM
  58.     Serial.print(address); // Print address
  59.     Serial.print("\t");
  60.     Serial.print(value, DEC); // Print value in decimal
  61.     Serial.println();
  62.  
  63.     address++; // Advance to the next address
  64.     if (address == EEPROM.length()) {
  65.         address = 0; // Wrap around if at the end
  66.     }
  67.  
  68.     delay(500); // Wait before next iteration
  69. }
  70.  
  71. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement