Advertisement
Juan_Blanc

I2CClock

Jul 12th, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*****************************/
  2. /*    KUBIK Software         */
  3. /*                           */
  4. /* Programado por Juan Blanc */
  5. /*                           */
  6. /*       Mayo 2016           */
  7. /*****************************/
  8.  
  9. #include <Wire.h>
  10. #include "RTClib.h"
  11. #include <LiquidCrystal_I2C.h>  
  12.  
  13. /* Creacion de objetos */
  14.  
  15. LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);//Direccion de LCD
  16.  
  17. RTC_DS1307 RTC;
  18.  
  19.  
  20. void setup () {
  21.   Wire.begin(); // Inicia el puerto I2C
  22.     RTC.begin(); // Inicia la comunicación con el RTC
  23.   lcd.begin(20,4); // Inicia el display lcd
  24.   //RTC.adjust(DateTime(__DATE__, __TIME__)); // Establece la fecha y hora (Comentar una vez establecida la hora)
  25.  
  26. }
  27. void loop(){
  28.  
  29.   int valorSensor = analogRead(A0);
  30.   DateTime now = RTC.now(); // Obtiene la fecha y hora del RTC
  31.   lcd.setCursor(0,0);
  32.   lcd.print(now.year(), DEC); // Año
  33.   lcd.print('/');
  34.   lcd.print(now.month(), DEC); // Mes
  35.   lcd.print('/');
  36.   lcd.print(now.day(), DEC); // Dia
  37.   lcd.print(' ');
  38.   lcd.setCursor(0,1);
  39.   lcd.print(now.hour(), DEC); // Horas
  40.   lcd.print(':');
  41.   lcd.print(now.minute(), DEC); // Minutos
  42.   lcd.print(':');
  43.   lcd.print(now.second(), DEC); // Segundos
  44.   lcd.setCursor(0,3);
  45.   lcd.print("Tension de pila RTC:");
  46.   float volt = valorSensor * (5.0 / 1023.0);
  47.   lcd.print(volt);
  48.   lcd.print("  [V]");
  49.   delay(10); // La información se actualiza cada 10 milisegundos
  50.  
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement