CurieTime Read Test

This example demonstrate how to use the CurieTime library methods.

Hardware Required

  • Arduino 101 Board

Code

1/*
2
3 * Copyright (c) 2016 Intel Corporation. All rights reserved.
4
5 * See the bottom of this file for the license terms.
6
7 */
8
9#include <CurieTime.h>
10
11void setup() {
12
13 Serial.begin(9600); // initialize Serial communication
14
15 while(!Serial) ; // wait for serial port to connect.
16
17 // set the current time to 14:27:00, December 14th, 2015
18
19 setTime(14, 27, 00, 14, 12, 2015);
20}
21
22void loop() {
23
24 Serial.print("Time now is: ");
25
26 print2digits(hour());
27
28 Serial.print(":");
29
30 print2digits(minute());
31
32 Serial.print(":");
33
34 print2digits(second());
35
36 Serial.print(" ");
37
38 Serial.print(day());
39
40 Serial.print("/");
41
42 Serial.print(month());
43
44 Serial.print("/");
45
46 Serial.print(year());
47
48 Serial.println();
49
50 delay(1000);
51}
52
53void print2digits(int number) {
54
55 if (number >= 0 && number < 10) {
56
57 Serial.print('0');
58
59 }
60
61 Serial.print(number);
62}
63
64/*
65
66 * Copyright (c) 2016 Intel Corporation. All rights reserved.
67
68 *
69
70 * This library is free software; you can redistribute it and/or
71
72 * modify it under the terms of the GNU Lesser General Public
73
74 * License as published by the Free Software Foundation; either
75
76 * version 2.1 of the License, or (at your option) any later version.
77
78 *
79
80 * This library is distributed in the hope that it will be useful,
81
82 * but WITHOUT ANY WARRANTY; without even the implied warranty of
83
84 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
85
86 * Lesser General Public License for more details.
87
88 *
89
90 * You should have received a copy of the GNU Lesser General Public
91
92 * License along with this library; if not, write to the Free Software
93
94 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
95
96 */

Contribute to Arduino

Join the community and suggest improvements to this article via GitHub. Make sure to read out contribution policy before making your pull request.

Missing something?

Check out our store and get what you need to follow this tutorial.

Suggest Changes

The content on docs.arduino.cc is facilitated through a public GitHub repository. You can read more on how to contribute in the contribution policy.