Skip to content

Instantly share code, notes, and snippets.

@choonewza
Last active January 22, 2020 05:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save choonewza/0eacdc5833e31b1628496ee65683a89a to your computer and use it in GitHub Desktop.
Save choonewza/0eacdc5833e31b1628496ee65683a89a to your computer and use it in GitHub Desktop.
Content CatLoRa Lab 7
#include <TimeLib.h>
#include <Wire.h>
#include <DS3231.h>
DS3231 clock;
char datetimeBuffer[32];
uint8_t seconds = 0;
void setup()
{
Serial.begin(115200);
delay(2000);
// Initialize DS3231
Serial.println("Initialize DS3231");
clock.begin();
if (clock.isReady() && Serial) {
clock.setDateTime(__DATE__, __TIME__);
}
}
void loop()
{
RTCDateTime dt = clock.getDateTime();
if (dt.second != seconds) {
seconds = dt.second;
//-----DateTime Format-----
sprintf(datetimeBuffer,
"%04d-%02d-%02d %02d:%02d:%02d",
dt.year,
dt.month,
dt.day,
dt.hour,
dt.minute,
dt.second);
//-----GET Temperature of DS3231-----
// The temperature registers are updated after every 64-second conversion.
// If you want force temperature conversion use forceConversion()
clock.forceConversion();
float temperature = clock.readTemperature();
//-----SHOW RESULT-----
Serial.print("DATE TIME : ");
Serial.println(datetimeBuffer);
Serial.print("UNIX TIME : ");
Serial.println(dt.unixtime);
Serial.print("TEMPERATURE : ");
Serial.print(temperature);
Serial.println(" C");
Serial.println();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment