Read string data EEPROM

Hello, i am doing a software that every time that someone turn on or off the switch, Arduino would store this information on the EEPROM, i already wrote the code to “write” on the EEPROM, but now is not working to read the information.

Here is the code to write:

#include <EEPROM.h>

#include <Time.h>
//#include <TimeAlarms.h>

String z = " ";
String x = ":";
String y = "/";
String w = "----";
String final = "";

const int buttonPin = 3;
int buttonState = 1;
int coco = 0;

int memoria = 1;

int ledPin = 8;


void setup()
{
  Serial.begin(19200);
  pinMode(ledPin, OUTPUT);
  setTime(8,29,0,24,8,2015);  


}

void  loop(){  

  ClockDisplay();
  
}

void ClockDisplay()
{
final = hour() + x + minute() + x + second() + z + day() + y + month() + y + year() + w;

buttonState = digitalRead(buttonPin);

if(buttonState != coco){
 coco = 1 - coco;
 for(int i = 0; i < final.length(); i++){
 EEPROM.write(memoria, final[i]);
 Serial.print(final[i]);
  memoria = memoria + 1;
 }

  
   }
  }


void printDigits(int digits)
{
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

void PrintDigits(int digits)
{
  
 Serial.print("/");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
  
}

Thanks

Part of the reason is because you don't have an EEPROM.read() function in your code.

What exactly are you having trouble with? If reading the EEPROM address where you wrote the input to it's pretty easy to do so with the EEPROM.read() function. You will however have to realize that EEPROM.write only writes a single byte to each address and EEPROM.read only reads a single byte. Meaning you will have to put each byte together to form your "string". Best done with a char array not a string though.

Bill

edit:econjack beat me to it lol

so wait, i am pretty new in all these things, so can you explain again how i can read that.
I know that the EEPROM only write and read byte per byte, but a did my String like a lot of bytes and wrote that right? Ok, so now, what is the code that i can use to read this information.
Thanks

First, get rid of the memory hog "Strings" and use char arrays.

char z[] = {"   "};
char x[] = {":"};
etc.

You want to save each byte to a separate address like

EEPROM.write(memoria1,final[0]);
EEPROM.write(memoria2,final[1]);
etc.

You are writing the contents of final to one address, memoria which erases the previous byte stored with the current/last byte written. You could use a for loop to write to address 1, then 2 and so on each consecutive byte of final. Then you read them back and place them into a char array.

Also, your button is not initialized in void setup. I make my buttons active when LOW.

void setup()
{
pinMode(button,INPUT_PULLUP);
}

Bill

When you say that i am saving in only one address, in the final i am putting, memoria = memoria + 1, which means that every loop is going to record on a different address.

if(buttonState != coco){
 coco = 1 - coco;
 for(int i = 0; i < final.length(); i++){
 EEPROM.write(memoria, final[i]);
 Serial.print(final[i]);
  memoria = memoria + 1;
 }

  
   }