Set up scheduled program cycles #24
|
@ -165,8 +165,8 @@ Timer<1> timer;
|
||||||
|
|
||||||
// Example from https://github.com/contrem/arduino-timer#examples
|
// Example from https://github.com/contrem/arduino-timer#examples
|
||||||
bool toggle_led(void *) {
|
bool toggle_led(void *) {
|
||||||
Serial.print("Timer time: ");
|
//Serial.print("Timer time: ");
|
||||||
Serial.println(rtc.now().timestamp());
|
//Serial.println(rtc.now().timestamp());
|
||||||
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); // toggle the LED
|
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); // toggle the LED
|
||||||
return true; // keep timer active? true
|
return true; // keep timer active? true
|
||||||
}
|
}
|
||||||
|
@ -562,7 +562,7 @@ void setup() {
|
||||||
rtc.adjust(DateTime(yourInputTime));
|
rtc.adjust(DateTime(yourInputTime));
|
||||||
// Might work to fix random errors? If date is far in the future,
|
// Might work to fix random errors? If date is far in the future,
|
||||||
// try to update again.
|
// try to update again.
|
||||||
while(rtc.now().year() > 2100){
|
while(rtc.now().year() > 2040){
|
||||||
Serial.println("RTC can't set time. Trying again.");
|
Serial.println("RTC can't set time. Trying again.");
|
||||||
rtc.adjust(DateTime(yourInputTime));
|
rtc.adjust(DateTime(yourInputTime));
|
||||||
}
|
}
|
||||||
|
@ -604,10 +604,16 @@ void setup() {
|
||||||
//}
|
//}
|
||||||
Serial.println(yourInputStartTimeUnix);
|
Serial.println(yourInputStartTimeUnix);
|
||||||
|
|
||||||
timer.at(millis() + 10000, toggle_led);
|
// We can't use arduino-timer for starting a program because
|
||||||
Serial.println(millis());
|
// it relies on millis(), which reset on power cycle.
|
||||||
auto active_tasks = timer.size();
|
// timer.at(millis() + 10000, toggle_led);
|
||||||
Serial.println(active_tasks);
|
// Serial.println(millis());
|
||||||
|
// auto active_tasks = timer.size();
|
||||||
|
// Serial.println(active_tasks);
|
||||||
|
|
||||||
|
// Use alarm built into RTC
|
||||||
|
rtc.setAlarm2(DateTime(yourInputStartTimeUnix), DS3231_A2_Date);
|
||||||
|
//rtc.setAlarm1(DateTime(2020, 6, 25, 15, 34, 0), DS3231_A2_Date);
|
||||||
}
|
}
|
||||||
// else {
|
// else {
|
||||||
// inputMessage = "No message sent";
|
// inputMessage = "No message sent";
|
||||||
|
@ -634,6 +640,21 @@ void loop() {
|
||||||
// Timers
|
// Timers
|
||||||
timer.tick();
|
timer.tick();
|
||||||
|
|
||||||
|
// This function from https://github.com/garrysblog/DS3231-Alarm-With-Adafruit-RTClib-Library/blob/master/DS3231-RTClib-Adafruit-Alarm-Poll-alarmFired/DS3231-RTClib-Adafruit-Alarm-Poll-alarmFired.ino
|
||||||
|
// Check if alarm by polling by using alarmFired
|
||||||
|
// We don't want old alarms, though.
|
||||||
|
//& (rtc.getAlarm2() >= rtc.now())
|
||||||
|
// if ((rtc.alarmFired(2) == 1) ){
|
||||||
|
|
||||||
|
// // Print current time and date
|
||||||
|
// DateTime now = rtc.now(); // Get the current time
|
||||||
|
// char buff[] = "Alarm triggered at hh:mm:ss DDD, DD MMM YYYY";
|
||||||
|
// Serial.println(now.toString(buff));
|
||||||
|
|
||||||
|
// // Disable and clear alarm
|
||||||
|
// rtc.clearAlarm(2);
|
||||||
|
// }
|
||||||
|
|
||||||
// DateTime now = rtc.now();
|
// DateTime now = rtc.now();
|
||||||
// Serial.print(now.year(), DEC);
|
// Serial.print(now.year(), DEC);
|
||||||
// Serial.print('/');
|
// Serial.print('/');
|
||||||
|
|
Loading…
Reference in New Issue
Block a user