/********* Pleasedontcode.com **********

	Pleasedontcode thanks you for automatic code generation! Enjoy your code!

	- Terms and Conditions:
	You have a non-exclusive, revocable, worldwide, royalty-free license
	for personal and commercial use. Attribution is optional; modifications
	are allowed, but you're responsible for code maintenance. We're not
	liable for any loss or damage. For full terms,
	please visit pleasedontcode.com/termsandconditions.

	- Project: **EEPROM Access**
	- Source Code NOT compiled for: Arduino Uno
	- Source Code created on: 2024-11-07 08:37:48

********* Pleasedontcode.com **********/

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* interfacing eeprom and intigrate with builtin one */
/****** END SYSTEM REQUIREMENTS *****/

/* START CODE */

/****** DEFINITION OF LIBRARIES *****/
#include <EEPROM.h>

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);

/****** GLOBAL VARIABLES *****/
int addr = 0; // Current address in the EEPROM for writing
int address = 0; // Current address in the EEPROM for reading
byte value; // Variable to store the read value

void setup(void)
{
    // Initialize serial communication for reading values
    Serial.begin(9600);
    while (!Serial) {
        ; // wait for serial port to connect. Needed for native USB port only
    }
}

void loop(void)
{
    // Write to EEPROM
    int val = analogRead(0) / 4; // Read analog input and scale
    EEPROM.write(addr, val); // Write value to EEPROM
    addr++; // Advance to the next address
    if (addr == EEPROM.length()) {
        addr = 0; // Wrap around if at the end
    }

    // Read from EEPROM
    value = EEPROM.read(address); // Read a byte from EEPROM
    Serial.print(address); // Print address
    Serial.print("\t");
    Serial.print(value, DEC); // Print value in decimal
    Serial.println();

    address++; // Advance to the next address
    if (address == EEPROM.length()) {
        address = 0; // Wrap around if at the end
    }

    delay(500); // Wait before next iteration
}

/* END CODE */