mirror of
https://github.com/taigrr/arduinolibs
synced 2025-01-18 04:33:12 -08:00
Add a timeout setting for the alarm
This commit is contained in:
parent
6e61524a0f
commit
054c59e3e8
@ -25,6 +25,7 @@
|
|||||||
#include <Form.h>
|
#include <Form.h>
|
||||||
#include <Field.h>
|
#include <Field.h>
|
||||||
#include <BoolField.h>
|
#include <BoolField.h>
|
||||||
|
#include <IntField.h>
|
||||||
#include <SoftI2C.h>
|
#include <SoftI2C.h>
|
||||||
#include <DS1307RTC.h>
|
#include <DS1307RTC.h>
|
||||||
#include <Melody.h>
|
#include <Melody.h>
|
||||||
@ -48,6 +49,7 @@
|
|||||||
|
|
||||||
// Offsets of settings in the realtime clock's NVRAM.
|
// Offsets of settings in the realtime clock's NVRAM.
|
||||||
#define SETTING_24HOUR 0 // 0: 12 hour, 1: 24 hour
|
#define SETTING_24HOUR 0 // 0: 12 hour, 1: 24 hour
|
||||||
|
#define SETTING_ALARM_TIMEOUT 1 // Timeout in minutes for the alarm
|
||||||
|
|
||||||
// Initialize the LCD
|
// Initialize the LCD
|
||||||
FreetronicsLCD lcd;
|
FreetronicsLCD lcd;
|
||||||
@ -75,6 +77,7 @@ SetAlarm alarm1(mainForm, "Alarm 1", 0);
|
|||||||
SetAlarm alarm2(mainForm, "Alarm 2", 1);
|
SetAlarm alarm2(mainForm, "Alarm 2", 1);
|
||||||
SetAlarm alarm3(mainForm, "Alarm 3", 2);
|
SetAlarm alarm3(mainForm, "Alarm 3", 2);
|
||||||
SetAlarm alarm4(mainForm, "Alarm 4", 3);
|
SetAlarm alarm4(mainForm, "Alarm 4", 3);
|
||||||
|
IntField alarmTimeout(mainForm, "Alarm timeout", 2, 10, 1, 2, " minutes");
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// Reduce power consumption on I/O pins we don't need.
|
// Reduce power consumption on I/O pins we don't need.
|
||||||
@ -98,14 +101,14 @@ void setup() {
|
|||||||
|
|
||||||
// Initialize the alarm melody.
|
// Initialize the alarm melody.
|
||||||
alarmMelody.setMelody(alarmNotes, alarmLengths, sizeof(alarmLengths));
|
alarmMelody.setMelody(alarmNotes, alarmLengths, sizeof(alarmLengths));
|
||||||
alarmMelody.setLoopDuration(120000UL);
|
|
||||||
//alarmMelody.play();
|
|
||||||
alarmMelody.stop(); // Force Timer2 to be disabled.
|
alarmMelody.stop(); // Force Timer2 to be disabled.
|
||||||
|
|
||||||
// Read the clock settings from the realtime clock's NVRAM.
|
// Read the clock settings from the realtime clock's NVRAM.
|
||||||
is24HourClock = rtc.readByte(SETTING_24HOUR) != 0;
|
is24HourClock = rtc.readByte(SETTING_24HOUR) != 0;
|
||||||
hourMode.setValue(is24HourClock);
|
hourMode.setValue(is24HourClock);
|
||||||
frontScreen.set24HourMode(is24HourClock);
|
frontScreen.set24HourMode(is24HourClock);
|
||||||
|
alarmTimeout.setValue(rtc.readByte(SETTING_ALARM_TIMEOUT));
|
||||||
|
alarmMelody.setLoopDuration(60000UL * alarmTimeout.value());
|
||||||
|
|
||||||
// Set the initial time and date and find the next alarm to be triggered.
|
// Set the initial time and date and find the next alarm to be triggered.
|
||||||
RTCTime time;
|
RTCTime time;
|
||||||
@ -160,6 +163,9 @@ void loop() {
|
|||||||
is24HourClock = hourMode.value();
|
is24HourClock = hourMode.value();
|
||||||
frontScreen.set24HourMode(is24HourClock);
|
frontScreen.set24HourMode(is24HourClock);
|
||||||
rtc.writeByte(SETTING_24HOUR, (byte)is24HourClock);
|
rtc.writeByte(SETTING_24HOUR, (byte)is24HourClock);
|
||||||
|
} else if (alarmTimeout.isCurrent()) {
|
||||||
|
rtc.writeByte(SETTING_ALARM_TIMEOUT, (byte)alarmTimeout.value());
|
||||||
|
alarmMelody.setLoopDuration(60000UL * alarmTimeout.value());
|
||||||
}
|
}
|
||||||
prevHour = 24; // Force an update of the main screen.
|
prevHour = 24; // Force an update of the main screen.
|
||||||
findNextAlarm(); // Update the time of the next alarm event.
|
findNextAlarm(); // Update the time of the next alarm event.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user