Thanks for reply,
I forgot to tell about my main target is that the data should overwrite on the location after 60 reading as per my plan ,
Actually there is one button, when I press ,want the previous 60 reading which I
continuously storing in EEPROM.
Whenever I press button its must show data of previous 60 reading from current timing and same work would to be carry forword with EEPROM to store data by overwriting on 1st reading of the EEPROM storage .then again for next iteration the data should efface for the 1st reading and write new one for current timing.
just like the following simple program that I write and read the data of 10 location and when I press button it shows the data for 5th location as per my code...
similarly when I press button then it will show the last 60 reading which is storing in EEPROM.
#include <EEPROM.h>
int addr = 0;
byte value;
int lastaddr = 40;
byte num [10]={1,2,3,4,5,6,7,8,9,10};
void setup()
{
Serial.begin(9600);
pinMode(9, INPUT_PULLUP);
}
void loop() {
//int adcvalue= analogRead(A0);
//float change=adcvalue*4.88;
//float temp = change/10;
//EEPROM.write(addr, array[i]);
for ( int i = 0; i < 10; ++i ){
EEPROM.write ( i, num[ i ] );
// value = EEPROM.read(addr);
//for ( int i = 0; i < 10; ++i )
EEPROM.read ( i);
Serial.print(i);
Serial.print("\t");
Serial.print(num [ i ], DEC);
Serial.println("\n");
}
if (digitalRead(9)==LOW){
Serial.println("After buttonpress :");
byte value= EEPROM.read (num [4]);
Serial.println(value);
}
//addr = addr + 1;
//if (addr == lastaddr) {
// addr = 0;
// }
delay(1000);
}
Thats it....
could you help me to change in your following [posted] code for button operation please ?
#include <Wire.h> //needed because DS3231 uses I2C Bus
#include <RTClib.h> //needed becuase we have ready-made functions of this librray
#include<EEPROM.h>
RTC_DS3231 rtc; //the object rtc is created from the class RTC_DS3231
//#define deviceAddress 0x68
//#define eepromAddress 0x0100
int eepromAddress = 0x0100;
struct
{
char myString1[50] = "temperature At: "; //16
byte hr; //nowTime.hour(); //1
char x1[5] = ":"; //1
byte mn; //nowTime.minute(); //1
char x2[5] = " "; //1
float myTemp; //4
char myString2[50] = " degC"; //5
} myVar, myVar2; //29
void setup()
{
Serial.begin(9600);
analogReference(DEFAULT);
//Serial.println(myVar.myString1);
if (! rtc.begin()) //DS3231 is intialized
{
while (1); //initialization failed
}
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));//auto update from computer time
// rtc.adjust(DateTime(2018, 12, 23, 21, 46, 17));//set date-time manualy:yr,mo,dy,hr,mn,se
}
void loop()
{
//--read Date and Tme from DS3231 using the method now()---------------------;
//--store the Date and Time into another user define object named nowTime
DateTime nowTime = rtc.now();
//-----------------------------------------------------
//Serial.print(myVar.myString1);//("temperature At: ");
myVar.hr = nowTime.hour();
// if (myVar.hr <= 9)
// {
// Serial.print("0");
//}
//Serial.print(myVar.hr);//nowTime.hour());
//Serial.print(myVar.x1);//(":");
myVar.mn = nowTime.minute();
//if (myVar.mn <= 9)
//{
// Serial.print("0");
// }
//Serial.print(myVar.mn);//(nowTime.minute());
Serial.print(myVar.x2);//(" ");
float tempC = (float)100 * (5 / 1024.0) * analogRead(A0);
myVar.myTemp = tempC;
// Serial.print(myVar.myTemp, 2);//(tempC, 2);
// Serial.print(myVar.myString2);//(" degC");
// Serial.println();
//---------------------------------------------------------
EEPROM.put(eepromAddress, myVar); //storing in EEPROM
EEPROM.get(eepromAddress, myVar2); //reading bcak the contents of EEPROM and put into myVar2
//--------------------------------------------------------
// Serial.println("==Reading back from EEPROM====");
Serial.print(myVar2.myString1);
if (myVar2.hr <= 9)
{
Serial.print("0");
}
Serial.print(myVar2.hr);//nowTime.hour());
Serial.print(myVar2.x1);//(":");
if (myVar2.mn <= 9)
{
Serial.print("0");
}
Serial.print(myVar2.mn);//(nowTime.minute());
Serial.print(myVar2.x2);
Serial.print(myVar2.myTemp, 2);//testing the correct operation on EEPROM
Serial.println(myVar2.myString2);
//Serial.println();
//Serial.println("=====Real Time Display======");
eepromAddress = eepromAddress + 32;
// eepromAddress = eepromAddress + sizeof(myVar.myString1)
// + sizeof(myVar.hr)+sizeof(myVar.x1) + sizeof(myVar.mn)
// + sizeof(myVar.x2)+sizeof(myVar.myTemp)
// + sizeof(myVar.myString2);
//Serial.print(eepromAddress, HEX);
// Serial.println("(New EEPROM Location)");
delay(59999);
}