Okay so I fixed it( the function for writing), i used a char array at the start instead of String but the problem now is that the function for reading isn't EVEN getting called.
#include<EEPROM.h>
String EEPROM_stringread(int addr) {
Serial.println("heckyeh");
int address = 0, eeprom_value;
Serial.println("heckyeh");
String eeprom_data = "";
while (1)
{
Serial.println("arduino");
eeprom_value = EEPROM.read(address);
if (eeprom_value == addr)
{
break;
}
eeprom_value = EEPROM.read(address + 1);
address = address + eeprom_value + 2;
}
eeprom_value = EEPROM.read(address + 1);
Serial.println(eeprom_value);
for (int i = address + 2; i <= address + eeprom_value + 1; i++)
{
Serial.println("yup");
char char_value;
EEPROM.get(i, char_value);
Serial.println(char_value);
eeprom_data = eeprom_data + char_value;
}
Serial.println("yes it works");
return eeprom_data;
}
String EEPROM_stringwrite(int addr, char char_array[]) {
int len = strlen(char_array), address = 0, counter = 0, eeprom_value;
//data = data + " ";
//++len;
//char char_array[len];
//data.toCharArray(char_array, len);
//--len;
do
{
eeprom_value = EEPROM.read(address);
Serial.println("yass");
if (eeprom_value == addr)
{
Serial.println("match");
++address;
eeprom_value = EEPROM.read(address);
if (eeprom_value > len)
{
Serial.println("small");
int current_address = address + eeprom_value + 1, new_address = address + len + 1, data_length, temp_value;
//new_address = current_address - eeprom_value + len;
while (EEPROM.read(current_address + 1) != 0)
{
EEPROM.put(new_address, EEPROM.read(current_address));
++new_address;
++current_address;
data_length = EEPROM.read(current_address);
EEPROM.put(new_address, data_length);
++new_address;
++current_address;
temp_value = current_address;
for (current_address; current_address <= temp_value + data_length - 1; current_address++)
{
char char_value;
EEPROM.get(current_address, char_value);
EEPROM.put(new_address, char_value);
++new_address;
}
}
}
else if (eeprom_value < len)
{
Serial.println("large");
int current_address, new_address = address + eeprom_value + 2, previous_address, data_length;
previous_address = new_address;
while (1)
{
data_length = EEPROM.read(new_address);
if (data_length == 0)
{
new_address = new_address + len - eeprom_value - 2;
if (new_address > EEPROM.length())
{
return "String too large";
}
else
{
break;
}
}
previous_address = new_address;
new_address = new_address + data_length + 2;
}
do
{
data_length = EEPROM.read(previous_address);
current_address = previous_address + data_length;
for (current_address; current_address >= previous_address + 1; current_address--)
{
char char_value;
EEPROM.get(current_address, char_value);
EEPROM.put(new_address, char_value);
--new_address;
}
EEPROM.put(new_address, EEPROM.read(current_address));
--new_address;
--current_address;
EEPROM.put(new_address, EEPROM.read(current_address));
int address_value = address + eeprom_value + 2, temp_value = previous_address;
while (address_value != temp_value)
{
data_length = EEPROM.read(address_value);
previous_address = address_value;
address_value = address_value + data_length + 2;
}
--new_address;
} while (current_address != address + eeprom_value + 1);
}
EEPROM.put(address, len);
for (int i = address + 1; i <= address + len; i++)
{
EEPROM.put(i, char_array[counter]);
++counter;
}
Serial.println("cmon");
return "Sucess";
}
eeprom_value = EEPROM.read(address + 1);
address = address + eeprom_value + 2;
} while (eeprom_value != 0);
Serial.println("normal");
address = 1;
while (1)
{
eeprom_value = EEPROM.read(address);
if (eeprom_value == 0)
{
break;
}
address = address + eeprom_value + 2;
}
if (address + len < EEPROM.length())
{
EEPROM.put(address - 1, addr);
EEPROM.put(address, len);
for (int i = address + 1; i <= address + len; i++)
{
EEPROM.write(i, char_array[counter]);
Serial.println(char_array[counter]);
++counter;
}
}
else
{
return "String too large";
}
Serial.println("cmon!");
}
void setup() {
Serial.begin(9600);
for (int i = 0 ; i < EEPROM.length() ; i++) {
EEPROM.write(i, 0);
}
Serial.println("done!");
EEPROM_stringwrite(11, "hello");
EEPROM_stringwrite(15, "world");
Serial.println("h");
EEPROM_stringwrite(9, "monster");
EEPROM_stringwrite(23, "saiyan");
EEPROM_stringwrite(30, "goku");
Serial.println("kami");
Serial.println(EEPROM.read(0));
char x;
EEPROM.get(2, x);
Serial.println(x);
String a;
/*EEPROM.get(2, a);
Serial.println(a);
*/
a = EEPROM_stringread(11);
Serial.println(a);
a = EEPROM_stringread(15);
Serial.println(a);
a = EEPROM_stringread(9);
Serial.println(a);
a = EEPROM_stringread(23);
Serial.println(a);
a = EEPROM_stringread(30);
Serial.println(a);
EEPROM_stringwrite(9, " ");
a = EEPROM_stringread(23);
Serial.println(a);
a = EEPROM_stringread(30);
Serial.println(a);
Serial.println("wat?!");
}
void loop() {
}
It's not even printing Serial.println("heckyeh"); (the read function) in Serial montior. What is this new error? Thanks