1
1
#include < CurieTime.h>
2
2
3
- const char *monthName[12 ] = {
4
- " Jan" , " Feb" , " Mar" , " Apr" , " May" , " Jun" ,
5
- " Jul" , " Aug" , " Sep" , " Oct" , " Nov" , " Dec"
6
- };
7
-
8
- int Hour, Min, Sec;
9
- int Day, Month, Year;
10
-
11
3
void setup () {
12
4
while (!Serial);
13
5
Serial.begin (9600 );
14
6
15
- // get the date and time the compiler was run
16
- if (getDate (__DATE__) && getTime (__TIME__)) {
17
- Serial.print (" Curie configured Time=" );
18
- Serial.print (__TIME__);
19
- Serial.print (" , Date=" );
20
- Serial.println (__DATE__);
21
-
22
- setTime (Hour, Min, Sec, Day, Month, Year);
23
- } else {
24
- Serial.print (" Could not parse info from the compiler, Time=\" " );
25
- Serial.print (__TIME__);
26
- Serial.print (" \" , Date=\" " );
27
- Serial.print (__DATE__);
28
- Serial.println (" \" " );
29
- }
7
+ // set the current time to 14:27:00, December 14th, 2015
8
+ setTime (14 , 27 , 00 , 14 , 12 , 2015 );
30
9
}
31
10
32
11
void loop () {
@@ -51,79 +30,6 @@ void loop() {
51
30
delay (1000 );
52
31
}
53
32
54
- bool getTime (const char *str)
55
- {
56
- // Get time from string of format HH:MM:SS
57
- String s = str;
58
-
59
- int firstColonIndex = s.indexOf (" :" );
60
- int lastColonIndex = s.lastIndexOf (" :" );
61
-
62
- if (firstColonIndex == -1 ) {
63
- // first colon not found
64
- return false ;
65
- }
66
-
67
- if (lastColonIndex == -1 ) {
68
- // last colon not found
69
- return false ;
70
- }
71
-
72
- if (firstColonIndex == lastColonIndex) {
73
- // only one colon, first and last index are the same
74
- return false ;
75
- }
76
-
77
- String hourString = s.substring (0 , firstColonIndex);
78
- String minuteString = s.substring (firstColonIndex + 1 , lastColonIndex);
79
- String secondString = s.substring (lastColonIndex + 1 );
80
-
81
- Hour = hourString.toInt ();
82
- Min = minuteString.toInt ();
83
- Sec = secondString.toInt ();
84
-
85
- return true ;
86
- }
87
-
88
- bool getDate (const char *str)
89
- {
90
- // Get Date from string of format MMM DD YYYY
91
- String s = str;
92
-
93
- int firstSpaceIndex = s.indexOf (" " );
94
- int lastSpaceIndex = s.lastIndexOf (" " );
95
-
96
- if (firstSpaceIndex == -1 ) {
97
- // first space not found
98
- return false ;
99
- }
100
-
101
- if (lastSpaceIndex == -1 ) {
102
- // last space not found
103
- return false ;
104
- }
105
-
106
- if (firstSpaceIndex == lastSpaceIndex) {
107
- // only one space, first and last index are the same
108
- return false ;
109
- }
110
-
111
- String monthString = s.substring (0 , firstSpaceIndex);
112
- String dayString = s.substring (firstSpaceIndex + 1 , lastSpaceIndex);
113
- String yearString = s.substring (lastSpaceIndex + 1 );
114
-
115
- for (Month = 1 ; Month <= 12 ; Month++) {
116
- if (monthString.equals (monthName[Month - 1 ])) {
117
- break ;
118
- }
119
- }
120
-
121
- Day = dayString.toInt ();
122
- Year = yearString.toInt ();
123
-
124
- return (Month <= 12 );
125
- }
126
-
127
33
void print2digits (int number) {
128
34
if (number >= 0 && number < 10 ) {
129
35
Serial.print (' 0' );
0 commit comments