mirror of
https://github.com/KevinMidboe/Arduino.git
synced 2025-10-29 17:40:11 +00:00
Init commit with many years of arduino sketches and projects. I dont know if the esp8266 includes much, but there are also libraries. I hope they dont have crazy automatic versioning through the Arduino IDE.
This commit is contained in:
47
Projects/libraries/Installed_libs/Time/Examples/TimeRTC/TimeRTC.pde
Executable file
47
Projects/libraries/Installed_libs/Time/Examples/TimeRTC/TimeRTC.pde
Executable file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* TimeRTC.pde
|
||||
* example code illustrating Time library with Real Time Clock.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <Time.h>
|
||||
#include <Wire.h>
|
||||
#include <DS1307RTC.h> // a basic DS1307 library that returns time as a time_t
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
setSyncProvider(RTC.get); // the function to get the time from the RTC
|
||||
if(timeStatus()!= timeSet)
|
||||
Serial.println("Unable to sync with the RTC");
|
||||
else
|
||||
Serial.println("RTC has set the system time");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
digitalClockDisplay();
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
void digitalClockDisplay(){
|
||||
// digital clock display of the time
|
||||
Serial.print(hour());
|
||||
printDigits(minute());
|
||||
printDigits(second());
|
||||
Serial.print(" ");
|
||||
Serial.print(day());
|
||||
Serial.print(" ");
|
||||
Serial.print(month());
|
||||
Serial.print(" ");
|
||||
Serial.print(year());
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void printDigits(int digits){
|
||||
// utility function for digital clock display: prints preceding colon and leading 0
|
||||
Serial.print(":");
|
||||
if(digits < 10)
|
||||
Serial.print('0');
|
||||
Serial.print(digits);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user