How to write a input counter data into EEPROM and retrieve it.?

Hi, am new to this forum, new to arduino itself. I am programming an input counter . My worry is in case of power failure, I need the date to be retrieved from EEPROM. So I am writing the date every second to the EEPROM. But am not able to read them.

#include <EEPROM.h>

#include "RTClib.h"
RTC_DS1307 RTC;
#include <LiquidCrystal.h>
LiquidCrystal
lcd(12,11,5,4,3,2);
const int inPin = 7;
float count1 = 0.00f;
float count2 = 0.00f;
int s=0;
int inState = 0;
int lastState = 0;
const long interval = 1000;
unsigned long previousTime = 0;
byte seconds;
byte minutes;
byte hours;
byte value;
int address;
//int sizeaddr=0;

void setup() {
//RTC.adjust(DateTime(DATE, TIME));
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// put your setup code here, to run once:
lcd.begin(16,2);
pinMode(inPin, INPUT);
}

void loop() {
// put your main code here, to run repeatedly:
address=0;
// sizeaddr=sizeof(count1);
EEPROM.put(address, count1);
//count1 = EEPROM.read(address);
// address = address + sizeaddr;
EEPROM.put(address+sizeof(count1), count2);
//count2 = EEPROM.read(address);

DateTime now = RTC.now();
seconds= now.second();
minutes=now.minute();
hours=now.hour();
if(seconds<30)
{
if(seconds==29)
{
count2=0;
lcd.setCursor(2,1);
lcd.print(" ");
}
inState = digitalRead(inPin);
if(inState!=lastState)
{
if(inState == HIGH)
{
count1++;
//while(digitalRead(inPin)==HIGH);
}
//delay(2);
}
lastState = inState;
}
if(seconds>30)
{
if(seconds==59)
{
count1=0;
lcd.setCursor(2,0);
lcd.print(" ");
}
inState = digitalRead(inPin);
if(inState!=lastState)
{
if(inState == HIGH)
{
count2++;
//while(digitalRead(inPin)==HIGH);
}
//delay(2);
}
lastState = inState;
}
lcd.setCursor(0,0);
lcd.print("A:");
EEPROM.get(address, count1);
lcd.print(count1/100);
lcd.setCursor(0,1);
lcd.print("B:");
EEPROM.get(address+sizeof(count1), count2);
lcd.print(count2/100);
lcd.setCursor(9,1);
lcd.setCursor(8,0);
lcd.print(hours);
lcd.print(":");
lcd.print(minutes);
lcd.print(":");
lcd.print(seconds);
}

Hi and welcome to the forum.
First of all, use the code tags for posting the code, please. It is leftmost button in edit window.

Without reading you code, consider that the EEPROM has limited number of writes to ~100000x. Writing the data each second wears the EEPROM rapidly (the day has 86400s), so the EEPROM is absolutely not suitable.

Look at this:

void loop() {
// put your main code here, to run repeatedly:
  address=0;
//  sizeaddr=sizeof(count1);
  EEPROM.put(address, count1);
//count1 = EEPROM.read(address);
// address = address + sizeaddr;
  EEPROM.put(address+sizeof(count1), count2);
//count2 = EEPROM.read(address);

What do you think, how many times the loop() runs in 1 second? This will destroy the cells in the EEPROM in a moment.
Fortunately put() method uses low level update function which writes only changes.

Yeah buddy. I think this loop will run every second.
Any ways to update the data to EEPROM only on power failure.??
Or may be on power failure , write to the RTC's memory?

in for info, im doing the same for a mileage save feature for a gauge panel

that loop will run how many times per second, its in the tens of thousands unless you have some sort of delay built in.....

Exactly as @mvpolo2k3 wrote. The loop runs many, many times in second. It depends on MCU's clock frequency, loop() length - number of instructions, interrupts, delays, sleep etc.

The DS1307 could be feasible for saving your data. It has 56 bytes of battery backed RAM with unlimited writes.

eeprom.read() reads a single byte; it's easier to use eeprom.get() which can read any data type (just like eeprom.put() can write any data type).