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 7The display code


The display() function works by checking if the hours variable can be divided by 16, if it can, it will turn on the LED representing 16, else turn it off. Then try dividing the remainder of the previous division with 8, turn the 8-led on if it could be divided, else off, divide the remainder of that division with 4 and so on.The same process is then repeated for minutes but starting at 32 instead of 16.

display() uses the hours_p and minutes_p pointers, that points to either the variables hours and minutes, or to the variables alarm_hours and alarm_minutes. What they are pointing to is decided in the settings switch code (in the buttons() function). So when the switch is turned to A (alarm), the display will automatically show the alarm time, and when it's turned back to T (time) the current time will be shown.
____________________________________________________________________

The display() function:

// "INTERNAL" VARIABLES FOR DISPLAY FUNCTION:
int remainder;
int led_value;

void display()
{
  // display() will display the ordinary time or the alarm time,
  // depending on what hours_p points to, this is decided
  // by the settings_switch_state, in the buttons() function
 
  // Display hours:
  remainder = *hours_p;
  for(int i = 0; i < 5; i++) // repeat four all five hour-LEDs
  {
    led_value = 16/round(pow(2,i)); // first LED = 16, second = 8, third = 4 etc.
   
    if(remainder/led_value == 1)
      digitalWrite(hour_pins[i], HIGH);
    else
      digitalWrite(hour_pins[i], LOW);
   
    // the remainder of the hours is saved for
    // the next LED that is displaying a lower value
    remainder=remainder%led_value;
  }
 
  // Display minutes:
  remainder = *minutes_p;
  for(int i = 0; i < 6; i++) // repeat for all six minute-LEDs
  {
    led_value = 32/round(pow(2,i)); // first 32, then 16, then 8 etc.
   
    if(remainder/led_value == 1)
      digitalWrite(minute_pins[i], HIGH);
    else
      digitalWrite(minute_pins[i], LOW);
   
    // the remainder of the minutes is saved for
    // the next LED that is displaying a lower value
    remainder=remainder%led_value;
  }
}
____________________________________________________________________
« 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