forked from FabioCuomo/FabioCuomo-DS3231
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
goertzel
committed
Jul 23, 2019
1 parent
2deadff
commit 9106293
Showing
3 changed files
with
189 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
|
||
// The PCF8523 alarm only supports down to minute resolution, no seconds | ||
|
||
|
||
#include <OPEnS_RTC.h> | ||
|
||
#define ALARM_PIN 6 | ||
|
||
|
||
// Instance of DS3231 RTC | ||
PCF8523 PCF; | ||
|
||
volatile bool alarmFlag = false; | ||
volatile int count = 0; | ||
void alarmISR() { | ||
// PCF.ackTimer1(); | ||
count++; | ||
alarmFlag = true; | ||
} | ||
|
||
|
||
void print_DateTime(DateTime time); | ||
|
||
|
||
|
||
// ======= SETUP ====== | ||
void setup() | ||
{ | ||
pinMode(ALARM_PIN, INPUT_PULLUP); // Pull up resistors required for Active-Low interrupts | ||
pinMode(LED_BUILTIN, OUTPUT); | ||
digitalWrite(LED_BUILTIN, HIGH); | ||
|
||
Serial.begin(115200); | ||
while (!Serial); // Won't start anything until serial is open, comment this line out if powering from battery | ||
|
||
PCF.begin(); | ||
PCF.adjust(DateTime(__DATE__, __TIME__)); | ||
|
||
PCF.setTimer1(eTB_SECOND, 5); | ||
|
||
attachInterrupt( digitalPinToInterrupt(ALARM_PIN), alarmISR, FALLING ); | ||
|
||
digitalWrite(LED_BUILTIN, LOW); | ||
Serial.println("Setup Complete"); | ||
} | ||
|
||
|
||
// ======= LOOP ====== | ||
void loop() | ||
{ | ||
if (alarmFlag) { | ||
digitalWrite(LED_BUILTIN, HIGH); | ||
Serial.println("Timer triggered, resetting alarm"); | ||
|
||
delay(2000); | ||
|
||
digitalWrite(LED_BUILTIN, LOW); | ||
alarmFlag = false; | ||
} | ||
Serial.print("Count: "); Serial.println(count); | ||
print_DateTime(PCF.now()); | ||
|
||
delay(1000); | ||
} | ||
|
||
|
||
// Print an RTC time | ||
void print_DateTime(DateTime time) | ||
{ | ||
Serial.print(time.year()); Serial.print('/'); | ||
Serial.print(time.month()); Serial.print('/'); | ||
Serial.print(time.day()); Serial.print(' '); | ||
Serial.print(time.hour()); Serial.print(':'); | ||
Serial.print(time.minute());Serial.print(':'); | ||
Serial.println(time.second()); | ||
} |