How can I modify the time in the program for DS1307?

HI everyone

I am a newbie of arudino programming. Starting a project to build a reef LED controller with arduino.

My arduino mega have a LCD ,a RTC 1307 module and 4 button. I would like to able to modify the time

with button instead of setting time during upload sketch from computer. I am using the RTClib but I found

there is not such function to write time. is there a way to write time to the DS1307?

You change the first 8 bytes of the memory to update the time. The datasheet for the device shows the mapping of that memory area.

I thought RTCLib had an adjust() method.

thank you all

i cannot find any how to document to use the RTC.adjust function. i think it is hard for me to write value to the memory area. i would like to know how to use RTC.adjust with what parameter.

i cannot find any how to document to use the RTC.adjust function.

You have the source code. Look at that.

i think it is hard for me to write value to the memory area.

You should not need to. That is what the adjust() method does.

i would like to know how to use RTC.adjust with what parameter.

That would be a method of a class contained in a library that you have not provided a link to. No can do.

The RTC.adjust() method takes a parameter of type DateTime.

    static void adjust(const DateTime& dt);

The library also provides functions to generate a DateTime value.

    DateTime (uint32_t t =0);
    DateTime (uint16_t year, uint8_t month, uint8_t day,  uint8_t hour =0, uint8_t min =0, uint8_t sec =0);
    DateTime (const char* date, const char* time);

For example, you can do something like:

RTC.adjust(DateTime(2012, 7, 12, 13, 25, 30));

thanks all. i try it

thank you it is working

RTC.adjust(DateTime(2012, 7, 12, 13, 25, 30));

How can i modify the hour and minute value only ? My program only need hour and minute like a alarm clock.

Read the current values and use them in the adjust().

RTC.adjust(DateTime(now.year(), now.month(),now.day() , set_time_hour,set_time_min ,now.second

set_time_hour and set_time_min are the modify value varible

is it what you mean?

is it what you mean?

Yes.