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 3Code Structure

Code Structure
«
  • Arduino_Duemilanove_0509.JPG
  • binary_clock_sketch_borders.png
I have divided the code for the clock into functions, one for each important bit of functionality. The functions are in separate tabs in the sketch. these are then run in the main loop:

void loop()
{
  clock();       // keep track of time, i.e. update hours, minutes and seconds variables as needed.
  display();   // display the time, or the alarm time, depending on the state of the settings switch.
  alarm();     // checks if it's time for the alarm  to start.
  update_buttons_state();   // checks if the buttons and touch sensor states has changed
  buttons();  // does what the buttons should do
} 

The variables that are needed by several functions are declared in the first tab (where setup() and loop() is) and the variables that are needed only by one function is declared in the same tab as that function.

If you change the DEBUG constant to 1 you will get some output via serial that can be good for troubleshooting, e.g. the time and what value the touchsensor returns.

I have tried to comment and make the code understandable but if you have questions or suggestions for improvements just leave a comment.

Here are the pins I used for the different parts:

- 2 and 4:  Touchsensor (4 is the send pin, 2 is recieve)
- 6              Hour button
- 5              Minute button
- 7              Switch
- 14-18      Display hour pins
- 8-13        Display minute pins

You can use whatever pins you want, just change in the code accordingly.
« 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