Step 11Alarm and snooze code
If snooze is active, the alarm function will also check if the current time is the same as the snooze off time, and if so, restart the alarm signal.
____________________________________________________________________
The alarm() function:
// "INTERNAL" VARIABLES FOR ALARM FUNCTION:
boolean first_time_signal_on = true; // used to make shure the signal is
// only started once, so that you can
// snooze without the alarm starting again
// imidiately.
void alarm()
{
if(alarm_on)
{
// Check if the time is same as alarm time:
if(hours==alarm_hours && minutes==alarm_minutes && first_time_signal_on)
{
// if so, turn on the alarm signal:
signal_on = true;
first_time_signal_on = false;
}
if(signal_on)
{
play_melody();
}
// look in buttons() for snooze button and alarm off button
if(snooze_on)
{
// Check if the time is same as snooze off time:
if(hours==snooze_off_hours && minutes==snooze_off_minutes)
{
// if so, turn off snooze and restart alarm signal:
snooze_on = false;
signal_on = true;
}
}
}
else
{
// reset so that the alarm will work next time:
first_time_signal_on = true;
}
}
_____________________________________________________________________
| « Previous Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|













































