//Enrico William A. Sihotang__COURSERA_Week 3
#include <EEPROM.h>

void setup()
{
  Serial.begin(9600);
}


int address;
int data;

void loop()
{
    String buffer = "";
    buffer = Serial.readString();

    if (buffer.startsWith("read"))
    {
        address = buffer.substring(buffer.indexOf("")+1).toInt();
        Serial.print("Data from the address");
        Serial.print(address);
        Serial.print("is");
        Serial.println(EEPROM.read(address));
    }
    else if (buffer.startsWith("write"))
    {
        address = buffer.substring(6,7).toInt();
        data = buffer.substring(8) .toInt();
        Serial.print("The data to be written on address");
        Serial.print(address);
        Serial.print("is");
        Serial.print(data);
        EEPROM.write(address,data);
    }
}