39 lines
1.1 KiB
C++
Executable File
39 lines
1.1 KiB
C++
Executable File
// Funciones de Hora y Fecha usando un RX8025 RTC conectado via I2C y libreria Wire
|
|
#include <Wire.h>
|
|
#include "RTClib.h"
|
|
|
|
RTC_DS3231 RTC; //Create the DS3231 object
|
|
|
|
char weekDay[][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
|
|
|
|
//year, month, date, hour, min, sec and week-day(starts from 0 and goes to 6)
|
|
//writing any non-existent time-data may interfere with normal operation of the RTC.
|
|
//Take care of week-day also.
|
|
DateTime dt(2018, 3, 20, 21, 51, 0);
|
|
|
|
void setup (){
|
|
Serial.begin(57600);
|
|
Wire.begin();
|
|
RTC.begin();
|
|
RTC.adjust(dt); //Adjust date-time as defined 'dt' above
|
|
}
|
|
|
|
void loop (){
|
|
DateTime now = RTC.now(); //get the current date-time
|
|
Serial.print(now.year(), DEC);
|
|
Serial.print('/');
|
|
Serial.print(now.month(), DEC);
|
|
Serial.print('/');
|
|
//Serial.print(now.date(), 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(weekDay[now.dayOfWeek()]);
|
|
Serial.println();
|
|
delay(1000);
|
|
}
|