Skip to content

Instantly share code, notes, and snippets.

@esmarr58
Created January 10, 2018 22:44
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 esmarr58/3864d2b97abb96e81061fcfd9472442d to your computer and use it in GitHub Desktop.
Save esmarr58/3864d2b97abb96e81061fcfd9472442d to your computer and use it in GitHub Desktop.
// 21/04/2015 Remodificado y probado por Roberto Chacón Diaz
// Pin Sda al pin A4 del arduino
// Pin Scl al pin A5 del arduino
// Tambien como en cualquier modulo, se deben conectar VCC y GND.
// Se aceptan sugerencias y/o modificaciones.
#include <LiquidCrystal.h>
#include <Wire.h>
#include "RTClib.h"
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);//pines del arduino al LCD (RS E D4 D5 D6 D7) RESPECTIVAMENTE
RTC_DS1307 RTC;
void setup()
{
Wire.begin(); //configura el bus I2C estableciendo arduino como MASTER
RTC.begin();
if (! RTC.isrunning()) // se verifica si el modulo rtc esta en funcionamiento, de lo contrario, se imprime: RTC is NOT running!
{
lcd.println("RTC is NOT running!");
delay(10000);
}
RTC.adjust(DateTime(__DATE__, __TIME__)); //esta funcion establecera en el modulo la fecha de creación del archivo .hex generado al compilar el sketch.
lcd.begin(16,2);
lcd.clear();
}
void loop()
{
mostrarRTCLCD(); //Se manda a llamar la funcion "mostrarRTCLCD" y despues se espera un tienpo de 1seg
delay(1000);
}
void mostrarRTCLCD() //Funcion que lee los datos de modulo RTC y despues los imprime en el display
{
DateTime now = RTC.now(); //obtiene datos del modulo RTC
lcd.clear();
lcd.setCursor(0,0);
if(now.day() < 10)
{
lcd.print("0");
}
lcd.print(now.day(), DEC); //imprime dia
lcd.print('/');
if(now.month() < 10)
{
lcd.print("0");
}
lcd.print(now.month(), DEC); //imprime mes
lcd.print('/');
lcd.print(now.year(), DEC); //imprime el año
lcd.setCursor(0,1);
if(now.hour() < 10)
{
lcd.print("0");
}
lcd.print(now.hour(), DEC); //imprime hora
lcd.print(':');
if(now.minute() < 10)
{
lcd.print("0");
}
lcd.print(now.minute(), DEC); //imprime minutos
lcd.print(':');
if(now.second() < 10)
{
lcd.print("0");
}
lcd.print(now.second(), DEC); //imprime segundos
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment