Skip to content

Commit

Permalink
Fixes and Examples
Browse files Browse the repository at this point in the history
* Epoch Bug fixes
* Added Examples
  • Loading branch information
cvmanjoo committed Jun 5, 2021
1 parent ad9ac60 commit e452d6a
Show file tree
Hide file tree
Showing 12 changed files with 709 additions and 214 deletions.
64 changes: 64 additions & 0 deletions examples/DS3231/DS3231_Auto/DS3231_Auto.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@

#include <Wire.h>
#include <RTC.h>

static DS3231 RTC;

void setup()
{
Serial.begin(9600);
RTC.begin();

//RTC.stopClock();

Serial.print("Is Clock Running: ");
if (RTC.isRunning())
{
Serial.println("Yes");
Serial.print(RTC.getDay());
Serial.print("-");
Serial.print(RTC.getMonth());
Serial.print("-");
Serial.print(RTC.getYear());
Serial.print(" ");
Serial.print(RTC.getHours());
Serial.print(":");
Serial.print(RTC.getMinutes());
Serial.print(":");
Serial.print(RTC.getSeconds());
Serial.print("");
if (RTC.getHourMode() == CLOCK_H12)
{
switch (RTC.getMeridiem()) {
case HOUR_AM:
Serial.print(" AM");
break;
case HOUR_PM:
Serial.print(" PM");
break;
}
}
Serial.println("");
delay(1000);
}
else
{
delay(200);

Serial.println("No");
Serial.println("Setting Time");
RTC.setHourMode(CLOCK_H12);
//RTC.setHourMode(CLOCK_H24);
RTC.setDateTime(__DATE__, __TIME__);
Serial.println("New Time Set");
Serial.print(__DATE__);
Serial.print(" ");
Serial.println(__TIME__);
RTC.startClock();
}
}

void loop()
{

}
47 changes: 47 additions & 0 deletions examples/DS3231/DS3231_Epoch/DS3231_Epoch.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <Wire.h>
#include <RTC.h>

static DS3231 RTC;

void setup()
{
Serial.begin(9600);
RTC.begin();

//RTC.setHourMode(CLOCK_H24);
RTC.setHourMode(CLOCK_H12);

//RTC.setEpoch(1622904335);
}

void loop()
{
Serial.println();
Serial.print("UnixTime : ");
Serial.println(RTC.getEpoch());

Serial.print(RTC.getDay());
Serial.print("-");
Serial.print(RTC.getMonth());
Serial.print("-");
Serial.print(RTC.getYear());

Serial.print(" ");

Serial.print(RTC.getHours());
Serial.print(":");
Serial.print(RTC.getMinutes());
Serial.print(":");
Serial.print(RTC.getSeconds());
Serial.print(" ");

if (RTC.getHourMode() == CLOCK_H12)
{
if(RTC.getMeridiem() == HOUR_AM)
Serial.println(" AM");
if (RTC.getMeridiem() == HOUR_PM)
Serial.println(" PM");
}

delay(1000);
}
2 changes: 1 addition & 1 deletion examples/DS3231/DS3231_Info/DS3231_Info.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void setup()
DateTime A1, A2;

Serial.println();
Serial.println("*** RTC 3231 ***");
Serial.println("*** RTC DS3231 ***");
Serial.print("Is Clock Running : ");
if (RTC.isRunning())
Serial.println("Yes");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,33 @@ void setup()
Serial.begin(9600);
RTC.begin();


RTC.setHourMode(CLOCK_H12);
//RTC.setHourMode(CLOCK_H24);

if (RTC.getHourMode() == CLOCK_H12)
{
// RTC.setMeridiem(HOUR_AM);
//RTC.setMeridiem(HOUR_PM);
}
/*
RTC.setDay(13);
RTC.setMonth(05);

RTC.setDay(22);
RTC.setMonth(5);
RTC.setYear(2020);

RTC.setHours(9);
RTC.setHours(23);
RTC.setMinutes(47);
RTC.setSeconds(56);
*/
RTC.setWeek(1);

RTC.setHourMode(CLOCK_H12);
//RTC.setHourMode(CLOCK_H24);
RTC.setWeek(1);

RTC.setDate(22,07,29);
//RTC.setDate(22,07,29);
//RTC.setTime(22,10,20);

RTC.setHours(22);



}

void loop()
{

switch (RTC.getWeek())
{
case 1:
Expand Down Expand Up @@ -81,15 +77,10 @@ void loop()

if (RTC.getHourMode() == CLOCK_H12)
{
switch (RTC.getMeridiem()) {
case HOUR_AM :
Serial.print(" AM");
break;
case HOUR_PM :
Serial.print(" PM");
break;
}
if(RTC.getMeridiem() == HOUR_AM)
Serial.println(" AM");
if (RTC.getMeridiem() == HOUR_PM)
Serial.println(" PM");
}
Serial.println("");
delay(1000);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
#include <Wire.h>
#include <RTC.h>

static DS3231 RTC;
static PCF8563 RTC;

void setup()
{
Serial.begin(9600);
RTC.begin();

//RTC.stopClock();

Serial.print("Is Clock Running: ");
if (RTC.isRunning())
{
Expand All @@ -25,17 +27,7 @@ void setup()
Serial.print(":");
Serial.print(RTC.getSeconds());
Serial.print("");
if (RTC.getHourMode() == CLOCK_H12)
{
switch (RTC.getMeridiem()) {
case HOUR_AM:
Serial.print(" AM");
break;
case HOUR_PM:
Serial.print(" PM");
break;
}
}

Serial.println("");
delay(1000);
}
Expand All @@ -45,8 +37,6 @@ void setup()

Serial.println("No");
Serial.println("Setting Time");
//RTC.setHourMode(CLOCK_H12);
RTC.setHourMode(CLOCK_H24);
RTC.setDateTime(__DATE__, __TIME__);
Serial.println("New Time Set");
Serial.print(__DATE__);
Expand Down
35 changes: 35 additions & 0 deletions examples/PCF8563/PCF8563_Epoch/PCF8563_Epoch.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <Wire.h>
#include <RTC.h>

static PCF8563 RTC;

void setup()
{
Serial.begin(9600);
RTC.begin();

//RTC.setEpoch(0);
}

void loop()
{
Serial.print("UnixTime : ");
Serial.println(RTC.getEpoch());

Serial.print(RTC.getDay());
Serial.print("-");
Serial.print(RTC.getMonth());
Serial.print("-");
Serial.print(RTC.getYear());

Serial.print(" ");

Serial.print(RTC.getHours());
Serial.print(":");
Serial.print(RTC.getMinutes());
Serial.print(":");
Serial.print(RTC.getSeconds());
Serial.println(" ");

delay(1000);
}
2 changes: 1 addition & 1 deletion examples/PCF8563/PCF8563_Info/PCF8563_Info.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void setup()
RTC.begin();

Serial.println();

Serial.println("*** RTC PCF8563 ***");
Serial.print("Is Clock Running : ");
if (RTC.isRunning())
Serial.println("Yes");
Expand Down
71 changes: 71 additions & 0 deletions examples/PCF8563/PCF8563_Manual/PCF8563_Manual.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include <Wire.h>
#include <RTC.h>

static PCF8563 RTC;

void setup() {

Serial.begin(9600);
RTC.begin();

/*
RTC.setDay(13);
RTC.setMonth(05);
RTC.setYear(2020);
RTC.setWeek(7); // Always Set weekday after setting Date
RTC.setHours(9);
RTC.setMinutes(47);
RTC.setSeconds(56);
*/

RTC.setDate(05, 06, 25); //SetDate(Day,Month,Year)
RTC.setTime(12, 14, 00); //SetTime(Hours,Minutes,Seconds)
RTC.setWeek(7); // Always Set weekday after setting Date

//RTC.setEpoch(0);
}

void loop() {
switch (RTC.getWeek()) {
case 1:
Serial.print("SUN");
break;
case 2:
Serial.print("MON");
break;
case 3:
Serial.print("TUE");
break;
case 4:
Serial.print("WED");
break;
case 5:
Serial.print("THU");
break;
case 6:
Serial.print("FRI");
break;
case 7:
Serial.print("SAT");
break;
}
Serial.print(" ");
Serial.print(RTC.getDay());
Serial.print("-");
Serial.print(RTC.getMonth());
Serial.print("-");
Serial.print(RTC.getYear());

Serial.print(" ");

Serial.print(RTC.getHours());
Serial.print(":");
Serial.print(RTC.getMinutes());
Serial.print(":");
Serial.print(RTC.getSeconds());
Serial.print(" ");

Serial.println("");
delay(1000);
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=RTC
version=1.0.1
version=1.0.2
author=Manjunath CV
maintainer=Manjunath CV <[email protected]>
sentence=Library for I2C based RTCs (DS1307, DS3231, PCF8563).
Expand Down
Loading

0 comments on commit e452d6a

Please sign in to comment.