Created
October 5, 2020 23:37
-
-
Save mgruben/86a64baab602d05c158956e27de2291b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Arduino DS3232RTC Library | |
// https://github.com/JChristensen/DS3232RTC | |
// | |
// Example sketch illustrating Time library with Real Time Clock. | |
// This example is identical to the example provided with the Time Library, | |
// only the #include statement has been changed to include the DS3232RTC library. | |
#include <DS3232RTC.h> // https://github.com/JChristensen/DS3232RTC | |
#include <LowPower.h> | |
// pin definitions | |
const uint8_t alarmInput(2); | |
const int LED_PIN = 8; | |
const int SQW_PIN = 2; | |
const int BUTTON_PIN = 3; | |
boolean alarm_1_called = false; | |
void turnLedOn() { | |
digitalWrite(LED_PIN, HIGH); | |
// Would perhaps be more convenient to call RTC.alarm(ALARM_1) here, | |
// but that breaks this ISR. | |
alarm_1_called = true; | |
} | |
void turnLedOff() { | |
digitalWrite(LED_PIN, LOW); | |
} | |
void setup() | |
{ | |
Serial.begin(115200); | |
// initialize the alarms to known values, clear the alarm flags, clear the alarm interrupt flags | |
RTC.setAlarm(ALM1_MATCH_DATE, 0, 0, 0, 1); | |
RTC.setAlarm(ALM2_MATCH_DATE, 0, 0, 0, 1); | |
RTC.alarm(ALARM_1); | |
RTC.alarm(ALARM_2); | |
RTC.alarmInterrupt(ALARM_1, false); | |
RTC.alarmInterrupt(ALARM_2, false); | |
RTC.squareWave(SQWAVE_NONE); | |
pinMode(SQW_PIN, INPUT_PULLUP); | |
pinMode(BUTTON_PIN, INPUT_PULLUP); | |
pinMode(LED_PIN, OUTPUT); | |
// set Alarm 1 to occur every second | |
RTC.setAlarm(ALM1_EVERY_SECOND, 0, 0, 0, 0); | |
// clear the alarm flag | |
RTC.alarm(ALARM_1); | |
// configure the INT/SQW pin for "interrupt" operation (disable square wave output) | |
RTC.squareWave(SQWAVE_NONE); | |
// enable interrupt output for Alarm 1 | |
RTC.alarmInterrupt(ALARM_1, true); | |
attachInterrupt(digitalPinToInterrupt(SQW_PIN), turnLedOn, FALLING); | |
attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), turnLedOff, FALLING); | |
} | |
void loop() | |
{ | |
if (alarm_1_called) | |
{ | |
RTC.alarm(ALARM_1); | |
} | |
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment