Go Down

Topic: changing clock/date setting on Real Time Clock pcf8563 [solved] (Read 2 times) previous topic - next topic

PaulS

Quote
If i can manipulate those at the byte level I think it might work?

What makes you think that? Have you tried anything? Where is your code, and a detailed explanation of what is/is not working, with serial output to prove it?

johncc


I dont think it's as simple as that. It looks like I need to set some sort of pointer to each of the variables "hour", "min","sec".


I don't see any pointers involved or needed here.
Code: [Select]

byte hr,min,sec;
void loop() {
   ... // warning untested code :)
   if (incrementMinuteButtonPressDectected) min = ++min % 60 // increment and rollover past 59
   if (decrementMinuteButtonPressDectected) min = (--min + 60) % 60 // decrement and rollunder past 0
   ...
   rtc.setTime( sec, min, hr);
   ...
}

mark7w

Code: [Select]
rtc.setTime(00, 30, 11)

In the snippet above, if I change the variables 00,30,11 to the current time. Then compile the sketch, the time on the lcd is updated. I am trying to get away from compiling the sketch each time JUST to update the "Time".

but I dont know how to enter the variables from my sketch AFTER it has been compliled.

the original sketch is here

Code: [Select]
/* Demonstration of Rtc_Pcf8563 Clock on LCD.
*

* This sketch connects a lcd to display the clock output.
*
* setup:  see Pcf8563 data sheet.
*         1x 10Kohm pullup on Pin3 INT
*         No pullups on Pin5 or Pin6 (I2C internals used)
*         1x 0.1pf on power
*         1x 32khz chrystal
*         1x h44780 LCD
*
* Joe Robertson, jmr
* orbitalair@bellsouth.net
*/

#include <Wire.h>
#include <Rtc_Pcf8563.h>
/* add the lcd support */
#include <LiquidCrystal.h>

//init the real time clock
Rtc_Pcf8563 rtc;

/* initialize the library objects */
LiquidCrystal lcd(7,8,9,10,11,12);

void setup()
{
  // set up the LCD's number of rows and columns:
  lcd.begin(16, 2);

  //clear out all the registers
  rtc.initClock();
  //set a time to start with.
  //day, weekday, month, century, year
  rtc.setDate(14, 6, 3, 0, 10);
  //hr, min, sec
  rtc.setTime(1, 15, 40);
}

void loop()
{
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 0);
  lcd.print(rtc.formatTime());
  lcd.setCursor(0, 1);
  lcd.print(rtc.formatDate());

  delay(1000);

}


I am going to use push buttons to change the "hour" "minute" and "sec". but "rtc.setTime(1, 15, 40);" how will the sketch know what 1,15,40 is. In the library these appear to be

Code: [Select]
setTime(byte sec, byte minute, byte hour)

so my thinking is byte sec, byte minute, byte hour tell ME what "(1, 15, 40)" are and therfore I would create a function to change byte sec, byte minute, byte hour byte

johncc

#8
Jan 20, 2013, 06:34 pm Last Edit: Jan 20, 2013, 06:42 pm by johncc Reason: 1

Code: [Select]
rtc.setTime(00, 30, 11)
I am going to use push buttons to change the "hour" "minute" and "sec". but "rtc.setTime(1, 15, 40);" how will the sketch know what 1,15,40 is. In the library these appear to be

so my thinking is byte sec, byte minute, byte hour tell ME what "(1, 15, 40)" are and therfore I would create a function to change byte sec, byte minute, byte hour byte


I think you have it backwards.  setTime() is for "you to tell it" what the time is.  For "it to tell you" what the time is, looks like you need to use rtc.getTime(); hr=rtc.getHour(); min=rtc.getMinute(); sec=rtc.getSecond(); [corrected]

Cheers,
John

PaulS

Write some simple code, in setup():

Code: [Select]
byte hour = 5;
byte min = 10;
byte sec = 14;

hour += 3;
min +=27;
sec +=10;

rtc.setTime(hour, min, sec);


What time does the RTC get set to? Read the time in loop(), and print the values.

Incrementing hour, min, and sec by other values is what you need to make the switches do.

Go Up