hello
may i present you with the project that i have been working on for 14 days and can't finish ![]()
it is quite exhausting i worked out a great code, but still don't work i want to consult you (experienced people). on why the code isn't working ![]()
I'm working on a code that can simply
write an order:"read ' address of EEPROM'" in the Serial Monitor and it reads out the data in this EEPROM address and print on Serial monitor
and another order
and
write another order:"write 'address of EEPROM' 'number i want to save in'" and it saves that number into the specified EEPROM memory
and here's my code i wish you can help me with why it is not working
void setup()
{
Serial.begin(9600);
Serial.println("This code allows you to read and write from the EEPROM memory");
/* add setup code here */
}
#include <EEPROM.h>
String command;
void loop()
{
if (Serial.available())
{
char c=Serial.read();
if (c=='\n')
{
parseCommand(command);
command="";
}
else
command+= c;
}
}
void parseCommand (String com)
{
String part1;
String part2;
String part3;
part1 = com.substring(0, com.indexOf(" "));
part2 = com.substring(com.indexOf(" ")+1);
if(part1.equalsIgnoreCase("read"))
{
int addressRead = part2.toInt();
int valueRead = EEPROM.read(addressRead);
Serial.print("\n");
Serial.print("ADDRESS:");
Serial.print(addressRead, DEC);
Serial.print("\t");
Serial.print("VALUE:");
Serial.print(valueRead, DEC);
}
else if(part1.equalsIgnoreCase("write"))
{
part2 = com.substring(com.indexOf(" ")+1);
part3 = part2.substring(part2.indexOf(" "));
String address=part2.substring(0,part2.indexOf(" "));
int addressWrite = address.toInt();
int valueWrite = part3.toInt();
EEPROM.write(addressWrite, valueWrite);
Serial.print("saved");
Serial.print(valueWrite, DEC);
Serial.print("to");
Serial.print(addressWrite, DEC);
}
else
{
Serial.println("COMMAND NOT RECOGNIZED");
}
}