mirror of
https://github.com/digistump/DigistumpArduino.git
synced 2025-09-17 17:32:25 -07:00
switch to setup for Arduino Boards Manager
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
// Simple date conversions and calculations
|
||||
|
||||
#include <TinyWireM.h>
|
||||
#include "TinyRTClib.h"
|
||||
|
||||
void showDate(const char* txt, const DateTime& dt) {
|
||||
Serial.print(txt);
|
||||
Serial.print(' ');
|
||||
Serial.print(dt.year(), DEC);
|
||||
Serial.print('/');
|
||||
Serial.print(dt.month(), DEC);
|
||||
Serial.print('/');
|
||||
Serial.print(dt.day(), DEC);
|
||||
Serial.print(' ');
|
||||
Serial.print(dt.hour(), DEC);
|
||||
Serial.print(':');
|
||||
Serial.print(dt.minute(), DEC);
|
||||
Serial.print(':');
|
||||
Serial.print(dt.second(), DEC);
|
||||
|
||||
Serial.print(" = ");
|
||||
Serial.print(dt.unixtime());
|
||||
Serial.print("s / ");
|
||||
Serial.print(dt.unixtime() / 86400L);
|
||||
Serial.print("d since 1970");
|
||||
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void setup () {
|
||||
Serial.begin(115200);
|
||||
|
||||
DateTime dt0 (0, 1, 1, 0, 0, 0);
|
||||
showDate("dt0", dt0);
|
||||
|
||||
DateTime dt1 (1, 1, 1, 0, 0, 0);
|
||||
showDate("dt1", dt1);
|
||||
|
||||
DateTime dt2 (2009, 1, 1, 0, 0, 0);
|
||||
showDate("dt2", dt2);
|
||||
|
||||
DateTime dt3 (2009, 1, 2, 0, 0, 0);
|
||||
showDate("dt3", dt3);
|
||||
|
||||
DateTime dt4 (2009, 1, 27, 0, 0, 0);
|
||||
showDate("dt4", dt4);
|
||||
|
||||
DateTime dt5 (2009, 2, 27, 0, 0, 0);
|
||||
showDate("dt5", dt5);
|
||||
|
||||
DateTime dt6 (2009, 12, 27, 0, 0, 0);
|
||||
showDate("dt6", dt6);
|
||||
|
||||
DateTime dt7 (dt6.unixtime() + 3600); // one hour later
|
||||
showDate("dt7", dt7);
|
||||
|
||||
DateTime dt8 (dt6.unixtime() + 86400L); // one day later
|
||||
showDate("dt8", dt8);
|
||||
|
||||
DateTime dt9 (dt6.unixtime() + 7 * 86400L); // one week later
|
||||
showDate("dt9", dt9);
|
||||
}
|
||||
|
||||
void loop () {
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
|
||||
|
||||
#include <TinyWireM.h>
|
||||
#include "TinyRTClib.h"
|
||||
|
||||
RTC_DS1307 RTC;
|
||||
|
||||
void setup () {
|
||||
Serial.begin(115200);
|
||||
TinyWireM.begin();
|
||||
RTC.begin();
|
||||
|
||||
if (! RTC.isrunning()) {
|
||||
Serial.println("RTC is NOT running!");
|
||||
// following line sets the RTC to the date & time this sketch was compiled
|
||||
RTC.adjust(DateTime(__DATE__, __TIME__));
|
||||
}
|
||||
}
|
||||
|
||||
void loop () {
|
||||
DateTime now = RTC.now();
|
||||
|
||||
Serial.print(now.year(), DEC);
|
||||
Serial.print('/');
|
||||
Serial.print(now.month(), DEC);
|
||||
Serial.print('/');
|
||||
Serial.print(now.day(), DEC);
|
||||
Serial.print(' ');
|
||||
Serial.print(now.hour(), DEC);
|
||||
Serial.print(':');
|
||||
Serial.print(now.minute(), DEC);
|
||||
Serial.print(':');
|
||||
Serial.print(now.second(), DEC);
|
||||
Serial.println();
|
||||
|
||||
Serial.print(" since midnight 1/1/1970 = ");
|
||||
Serial.print(now.unixtime());
|
||||
Serial.print("s = ");
|
||||
Serial.print(now.unixtime() / 86400L);
|
||||
Serial.println("d");
|
||||
|
||||
// calculate a date which is 7 days and 30 seconds into the future
|
||||
DateTime future (now.unixtime() + 7 * 86400L + 30);
|
||||
|
||||
Serial.print(" now + 7d + 30s: ");
|
||||
Serial.print(future.year(), DEC);
|
||||
Serial.print('/');
|
||||
Serial.print(future.month(), DEC);
|
||||
Serial.print('/');
|
||||
Serial.print(future.day(), DEC);
|
||||
Serial.print(' ');
|
||||
Serial.print(future.hour(), DEC);
|
||||
Serial.print(':');
|
||||
Serial.print(future.minute(), DEC);
|
||||
Serial.print(':');
|
||||
Serial.print(future.second(), DEC);
|
||||
Serial.println();
|
||||
|
||||
Serial.println();
|
||||
delay(3000);
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
// Date and time functions using just software, based on millis() & timer
|
||||
|
||||
#include <TinyWireM.h>
|
||||
#include "TinyRTClib.h"
|
||||
|
||||
RTC_Millis RTC;
|
||||
|
||||
void setup () {
|
||||
Serial.begin(115200);
|
||||
// following line sets the RTC to the date & time this sketch was compiled
|
||||
RTC.begin(DateTime(__DATE__, __TIME__));
|
||||
}
|
||||
|
||||
void loop () {
|
||||
DateTime now = RTC.now();
|
||||
|
||||
Serial.print(now.year(), DEC);
|
||||
Serial.print('/');
|
||||
Serial.print(now.month(), DEC);
|
||||
Serial.print('/');
|
||||
Serial.print(now.day(), DEC);
|
||||
Serial.print(' ');
|
||||
Serial.print(now.hour(), DEC);
|
||||
Serial.print(':');
|
||||
Serial.print(now.minute(), DEC);
|
||||
Serial.print(':');
|
||||
Serial.print(now.second(), DEC);
|
||||
Serial.println();
|
||||
|
||||
Serial.print(" seconds since 1970: ");
|
||||
Serial.println(now.unixtime());
|
||||
|
||||
// calculate a date which is 7 days and 30 seconds into the future
|
||||
DateTime future (now.unixtime() + 7 * 86400L + 30);
|
||||
|
||||
Serial.print(" now + 7d + 30s: ");
|
||||
Serial.print(future.year(), DEC);
|
||||
Serial.print('/');
|
||||
Serial.print(future.month(), DEC);
|
||||
Serial.print('/');
|
||||
Serial.print(future.day(), DEC);
|
||||
Serial.print(' ');
|
||||
Serial.print(future.hour(), DEC);
|
||||
Serial.print(':');
|
||||
Serial.print(future.minute(), DEC);
|
||||
Serial.print(':');
|
||||
Serial.print(future.second(), DEC);
|
||||
Serial.println();
|
||||
|
||||
Serial.println();
|
||||
delay(3000);
|
||||
}
|
Reference in New Issue
Block a user