-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathSparkTimeExample.cpp
More file actions
53 lines (48 loc) · 1.3 KB
/
SparkTimeExample.cpp
File metadata and controls
53 lines (48 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// This #include statement was automatically added by the Spark IDE.
#include "SparkTime.h"
UDP UDPClient;
SparkTime rtc;
unsigned long currentTime;
unsigned long lastTime = 0UL;
String timeStr;
void setup() {
rtc.begin(&UDPClient, "north-america.pool.ntp.org");
rtc.setTimeZone(-5); // gmt offset
Serial.begin(9600);
}
void loop() {
currentTime = rtc.now();
if (currentTime != lastTime) {
byte sec = rtc.second(currentTime);
if (sec == 10) {
// Build Date String
timeStr = "";
timeStr += rtc.dayOfWeekString(currentTime);
timeStr += ", ";
timeStr += rtc.monthNameString(currentTime);
timeStr += " ";
timeStr += rtc.dayString(currentTime);
timeStr += ", ";
timeStr += rtc.yearString(currentTime);
Serial.print(timeStr);
} else if (sec == 40) {
// Including current timezone
Serial.print(rtc.ISODateString(currentTime));
} else if (sec == 50) {
// UTC or Zulu time
Serial.print(rtc.ISODateUTCString(currentTime));
} else {
// Just the time in 12 hour format
timeStr = "";
timeStr += rtc.hour12String(currentTime);
timeStr += ":";
timeStr += rtc.minuteString(currentTime);
timeStr += ":";
timeStr += rtc.secondString(currentTime);
timeStr += " ";
timeStr += rtc.AMPMString(currentTime);
Serial.print(timeStr);
}
lastTime = currentTime;
}
}