/** Return hours left of the alarm timer if it is set. */ int Clock::GetAlarmHour(){ if(!GetAlarmIsRunning()){ return 0; } TimeSpan timeBetweenNowAndAlarm = _alarm - rtc.now(); if(timeBetweenNowAndAlarm.hours() >= 0){ return timeBetweenNowAndAlarm.hours(); } return 0; }
void AlarmService::checkAlarm(DateTime& now) { if (digitalRead(buttonPin) == HIGH && isAlarmSet()) { free(alarm); alarm = NULL; } if (isAlarmSet()) { TimeSpan diff = DateTime(now.year(), now.month(), now.day(), alarm->hour(), alarm->minute(), 0) - DateTime(now.year(), now.month(), now.day(), now.hour(), now.minute(), now.second()); if (diff.hours() == 0 && diff.minutes() > -5 && diff.seconds() <= 0) { play(); } } }