#include <EEPROM.h>
void writeStringToEEPROM(int address, String data) {
// Iterate over each character in the string
for (int i = 0; i < data.length(); i++) {
EEPROM.write(address + i, data[i]);
}
// Write the null terminator to mark the end of the string
EEPROM.write(address + data.length(), '\0');
}
String readStringFromEEPROM(int address) {
String data = "";
char character;
// Read each character from EEPROM until null terminator is encountered
while ((character = EEPROM.read(address)) != '\0' && address < EEPROM.length()) {
data += character;
address++;
}
return data;
}
void setup() {
Serial.begin(9600);
// Example: Save a string to EEPROM
String myString = "Hello, Arduino!";
writeStringToEEPROM(0, myString);
// Example: Read the string from EEPROM and print it
String retrievedString = readStringFromEEPROM(0);
Serial.println("Retrieved String from EEPROM: " + retrievedString);
}
void loop() {
// Your code here
}