I have been wondering if I there is any way I can store the current time in an array. Im using ds1307 rtc module.
Im trying to do a code which required the user to input and set a date using keypad (the data will be store in an array) for the arduino to unlock a door. If the date today is not equal to the set date, the door will not be unlock. Im planning to do a comparison of the current date to the set date which is store in array so when the date is equal the door will unlock.
Is there a way to store the current date in an array? If not please share another way how achieve the goal.
Is there any link or website I can refer to? Please give examples on how to store current date in an array.
I have been wondering if I there is any way I can store the current time in an array.
What kind of array? What representation of the current time?
What kind of array is the user-entered data being stored in?
The DS1307 has 7 registers with date & time info.
Address 0: tens of seconds, units of seconds
Address 1: tens of minutes, units of minutes
Address 2: tens of hours, units of hours
Address 3: Day of week, 01 to 07
Address 4: tens of day of month, units of day of month
Address 5: tens of month, units of month
Address 6: tens of year, units of year
So simplest is to read addresses 4,5,6, convert into whole numbers and store as 3 bytes,
total days, total month, total year.
Ranges will be days 1-31, month 1-12, and year 0 to 99.
A struct is a better container for time than an array. There is one already defined for you in the Time library. You can use it or study it.
qistie:
Is there a way to store the current date in an array? If not please share another way how achieve the goal.
Is there any link or website I can refer to? Please give examples on how to store current date in an array.
an easy way would be to store a UNIX timestamp (unsigned long).
Call a function that calculates it for midnight
time_t today = makeTimestamp(year(), month(), day(), 0, 0, 0);
with a function that makes the timestamp like this example:
time_t DailyTimer::tmConvert_t(int YYYY, byte MM, byte DD, byte hh, byte mm, byte ss)
{
tmElements_t tmSet;
tmSet.Year = YYYY - 1970;
tmSet.Month = MM;
tmSet.Day = DD;
tmSet.Hour = hh;
tmSet.Minute = mm;
tmSet.Second = ss;
return makeTime(tmSet);
}