Let's take the Simple Watch example, and tweak it to use the O-Watch's built-in Real-Time Clock (RTC).
It is strongly recommended that you get the Simple Watch example working on your watch before trying this one.
NOTE: If you are seeing errors with RTCZero.cpp failing to compile, see the comments below.
(When you get this project working, if you'd like a LOT of watch faces to choose from, check out Mult-O-Watch.)
By itself, the Arduino Zero processor at the heart of the O-Watch can keep pretty good time just by counting to itself. This is how the Simple Watch example works. If you let your O-Watch run Simple Watch for a few hours, you'll probably notice that its time is off by a few minutes. So, it does a pretty good job of keeping track of time, but not great.
But the O-Watch--because it is based on the Arduino Zero--also has a Real-Time Clock chip built-in, which keeps extremely accurate time. So, let's use it!
To do that, we'll need to include the Arduino Zero's RTC library. You can do either of the following:
- In the Arduino IDE, go to the 'Sketch' menu, then select the 'Include Library' menu item, then select the 'Manage Libraries...' item from the sub-menu. In the Library Manager window, search for 'RTCZero', and click the 'Install' library if it isn't yet installed.
- Or, if that doesn't work, download the RTC library in a .ZIP file from here. Once you've downloaded it, extract the contents, and copy them to your Documents -> Arduino -> Libraries folder just like you did with the Arduino Time Library for the Simple Watch demo.
To make this example work just like Simple Watch does, we're going to use both the RTC and the Time libraries. We'll use the RTC library to do most of the timekeeping work, but we'll still use the Time library to display the day of the week.
While we're tweaking things, we'll make a few more changes:
- The O-Watch will display the current date and time whenever you push any of its 4 buttons. You can change this so that the buttons do different things if you'd like, but we'll start off simple.
- When you push a button, the watch will display the time for 5 seconds, and will update the seconds counter every second.
- Rather than having to hand-edit the current (starting) time in the .INO source code, we'll let the Arduino compiler (which is really a C++ compiler under the hood) use the C++ __DATE__ and __TIME__ predefined macro strings to set it for us. These contain the current date and time in formats like 'Mar 13 2016' for the current date and '09:45:17' for the current time. Because these are strings, we'll need to do a little work to get the numbers we need out of them, but it's worth it to not have to keep re-editing the source code.
- The O-Watch can control how bright its display is, from 1 (dim) to 15 (bright). We'll add a little code to set the brightness based on time of day. It'll be dim (3) at midnight and gradually get brighter throughout the morning until it is bright (15) at noon, then stay fully bright all afternoon until 6 PM, after which it will gradually get dimmer until it is back to 3 by midnight.
Comments