-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add time support (time, gettimeofday, etc.) (#138)
- Loading branch information
1 parent
0550fe7
commit af8b548
Showing
2 changed files
with
48 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* Simple demonstration of setting and printing the current time */ | ||
/* The initial time will need to come from an RTC, NTP, or user */ | ||
|
||
/* Released to the public domain by Earle F. Philhower, III <earlephilhower@yahoo.com> */ | ||
|
||
#include <time.h> | ||
#include <sys/time.h> | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
delay(5000); | ||
struct timeval tv; | ||
|
||
tv.tv_sec = 1611198855; // Jan 21, 2021 3:14:15AM ...RPi Pico Release; | ||
tv.tv_usec = 0; | ||
settimeofday(&tv, nullptr); | ||
} | ||
|
||
void loop() { | ||
time_t now; | ||
struct tm *info; | ||
char buff[80]; | ||
|
||
time(&now); | ||
strftime(buff, sizeof(buff), "%c", localtime(&now)); | ||
Serial.println(buff); | ||
delay(1000); | ||
} |