O Watch Programming: Basic Watch

Let us start with a basic watch program. The way the watch works is you first set the time and date on the micro-controller and then retrieve the current value when you need to show it.

We will use the Arduino Time Library to make the watch program.

First downloaded the latest version of Arduino Time library.
Unzip the folder and rename it to ‘Time”. Place the folder under Documents->Arduino->Library.

When we adapt a standard Arduino program for O Watch, you need to keep in mind two things: a) Include and Initialize the TinyScreen library and b) All output will be via the TinyScreen display.

Simple Watch 1

SimpleWatch

You can copy and paste the above program in to your Arduino IDE and upload it to O Watch.

The following are the main functions used here from the Arduino Time library.

  • setTime(hr,min,sec,day,mnth,yr): Sets the time
  • hour(): The hour now (0-23)
  • minute(): The minute now (0-59)
  • second(): The second now (0-59)
  • day(): The day now (1-31)
  • weekday(): Day of the week, Sunday is day 0
  • month(): The month now (1-12)
  • year() The full four digit year: (2009, 2010 etc)
  • monthStr(month()): Gives the month as text string for the retrieved month() value
  • dayStr(day()): Gives the month as text string for the retrieved day() value

 

Simple Watch 2

Now let us take it a step forward and write a watch with functions to update the time and date. In this we will also see how to use the buttons to select the part of the program (or function) you want to run. We will also see how to use the Arduino for and switch/case statements.

Note the following from this second program:

  • User Defined Functions: You see two functions updateTime() and updateDate() that are written by the user and called from the main loop.
  • Switch/Case: The use of Arduino Switch/Case statements to select the code block/function you want to run.
  • For: Arduino for statements to create a loop for a specific number of runs.
  • display.on() and off(): We use these TinyScreen functions to switch off the display when not needed to conserve power.

There you have your basic digital watch that can last most of the day. Hope this gives you enough of an idea to make your own versions of the watch.

This is a simple digital watch using the Arduino Time Library that essentially keeps time using an internal counter in the Arduino micro-controller. Though this is fairly accurate, you will notice the time drift a by a minute or two every hour. To keep accurate time you need to use the Arduino RTC library that uses the Real-Time-Clock built into the O Watch main board. Refer to this O Watch RTC example from J Koger, one of our awesome backers.

<< Back: TinyScreen Functions | Next: Adding a Game >>