3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Arduino Binary Alarm Clock

Step 11Alarm and snooze code

If the alarm is active (alarm_on variable is set to true), the alarm() function will check if the current time is the same as the set alarm time. If it is, the signal_on variable will be set to true. If the signal_on variable is true, the function will call the play_melody() function.
 
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 StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
2
Followers
1
Author:njakol