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);
}