forked from adafruit/RTClib
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Incorporated DS3231 (Chronodot), DS3234 functions from Coobro
- Loading branch information
Showing
11 changed files
with
851 additions
and
13 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,49 @@ | ||
// Date, Time and Alarm functions using a DS3231 RTC connected via I2C and Wire lib | ||
|
||
#include <Wire.h> | ||
#include <SPI.h> // not used here, but needed to prevent a RTClib compile error | ||
#include <RTClib.h> | ||
|
||
RTC_DS3231 RTC; | ||
|
||
void setup () { | ||
Serial.begin(57600); | ||
Wire.begin(); | ||
RTC.begin(); | ||
|
||
RTC.adjust(DateTime(__DATE__, __TIME__)); | ||
if (! RTC.isrunning()) { | ||
Serial.println("RTC is NOT running!"); | ||
// following line sets the RTC to the date & time this sketch was compiled | ||
RTC.adjust(DateTime(__DATE__, __TIME__)); | ||
} | ||
DateTime now = RTC.now(); | ||
RTC.setAlarm1Simple(21, 58); | ||
RTC.turnOnAlarm(1); | ||
if (RTC.checkAlarmEnabled(1)) { | ||
Serial.println("Alarm Enabled"); | ||
} | ||
} | ||
|
||
void loop () { | ||
DateTime now = RTC.now(); | ||
|
||
Serial.print(now.year(), DEC); | ||
Serial.print('/'); | ||
Serial.print(now.month(), DEC); | ||
Serial.print('/'); | ||
Serial.print(now.day(), DEC); | ||
Serial.print(' '); | ||
Serial.print(now.hour(), DEC); | ||
Serial.print(':'); | ||
Serial.print(now.minute(), DEC); | ||
Serial.print(':'); | ||
Serial.print(now.second(), DEC); | ||
Serial.println(); | ||
|
||
if (RTC.checkIfAlarm(1)) { | ||
Serial.println("Alarm Triggered"); | ||
} | ||
Serial.println(); | ||
delay(3000); | ||
} |
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,63 @@ | ||
// Date, Time and Alarm functions using a DS3231 RTC connected via I2C and Wire lib | ||
|
||
#include <Wire.h> | ||
#include <SPI.h> // not used here, but needed to prevent a RTClib compile error | ||
#include <avr/sleep.h> | ||
#include <RTClib.h> | ||
|
||
|
||
RTC_DS3231 RTC; | ||
int INTERRUPT_PIN = 2; | ||
volatile int state = LOW; | ||
|
||
void setup () { | ||
pinMode(INTERRUPT_PIN, INPUT); | ||
//pull up the interrupt pin | ||
digitalWrite(INTERRUPT_PIN, HIGH); | ||
|
||
Serial.begin(57600); | ||
Wire.begin(); | ||
RTC.begin(); | ||
|
||
RTC.adjust(DateTime(__DATE__, __TIME__)); | ||
DateTime now = RTC.now(); | ||
RTC.setAlarm1Simple(22, 11); | ||
RTC.setAlarm2Simple(11, 10); | ||
RTC.turnOnAlarm(1); | ||
RTC.turnOnAlarm(2); | ||
if (RTC.checkAlarmEnabled(1) && RTC.checkAlarmEnabled(2)) { | ||
Serial.println("Alarms Enabled"); | ||
} | ||
attachInterrupt(0, logData, LOW); | ||
} | ||
|
||
void loop () { | ||
DateTime now = RTC.now(); | ||
if (RTC.checkIfAlarm(1) || RTC.checkIfAlarm(2)) { | ||
Serial.println("Alarm Triggered"); | ||
} | ||
|
||
Serial.print(now.hour(), DEC); | ||
Serial.print(':'); | ||
Serial.print(now.minute(), DEC); | ||
Serial.print(':'); | ||
Serial.println(now.second(), DEC); | ||
Serial.println("Going to Sleep"); | ||
delay(600); | ||
sleepNow(); | ||
Serial.println("AWAKE"); | ||
} | ||
|
||
void sleepNow() { | ||
set_sleep_mode(SLEEP_MODE_PWR_DOWN); | ||
sleep_enable(); | ||
attachInterrupt(0,logData, LOW); | ||
sleep_mode(); | ||
//HERE AFTER WAKING UP | ||
sleep_disable(); | ||
detachInterrupt(0); | ||
} | ||
|
||
void logData() { | ||
//do something quick, flip a flag, and handle in loop(); | ||
} |
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,57 @@ | ||
// Date and time functions using a DS3234 RTC connected via SPI | ||
|
||
#include <SPI.h> | ||
#include <Wire.h> // not used here, but needed to prevent a RTClib compile error | ||
#include <RTClib.h> | ||
|
||
|
||
// Avoid spurious warnings | ||
#undef PROGMEM | ||
#define PROGMEM __attribute__(( section(".progmem.data") )) | ||
#undef PSTR | ||
#define PSTR(s) (__extension__({static prog_char __c[] PROGMEM = (s); &__c[0];})) | ||
|
||
// Create an RTC instance, using the chip select pin it's connected to | ||
RTC_DS3234 RTC(8); | ||
|
||
void setup () { | ||
Serial.begin(57600); | ||
Serial.println("RTClib/examples/ds3234/"); | ||
SPI.begin(); | ||
RTC.begin(); | ||
|
||
if (! RTC.isrunning()) { | ||
Serial.println("RTC is NOT running!"); | ||
Serial.print("Setting time to... "); | ||
Serial.print(__DATE__); | ||
Serial.print(' '); | ||
Serial.println(__TIME__); | ||
// following line sets the RTC to the date & time this sketch was compiled | ||
RTC.adjust(DateTime(__DATE__, __TIME__)); | ||
} | ||
} | ||
|
||
void loop () { | ||
const int len = 32; | ||
static char buf[len]; | ||
|
||
DateTime now = RTC.now(); | ||
|
||
Serial.println(now.toString(buf,len)); | ||
|
||
Serial.print(" since midnight 1/1/1970 = "); | ||
Serial.print(now.unixtime()); | ||
Serial.print("s = "); | ||
Serial.print(now.unixtime() / 86400L); | ||
Serial.println("d"); | ||
|
||
// calculate a date which is 7 days and 30 seconds into the future | ||
DateTime future (now.unixtime() + 7 * 86400L + 30 ); | ||
|
||
Serial.print(" now + 7d + 30s: "); | ||
Serial.println(future.toString(buf,len)); | ||
|
||
Serial.println(); | ||
delay(3000); | ||
} | ||
|
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
Oops, something went wrong.