Advertisement
Jorge_moises

Relogio LCD 16x2

Aug 9th, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <Wire.h>
  2. #include "RTClib.h"
  3. #include <LiquidCrystal.h>
  4.  
  5. RTC_DS1307 RTC;
  6. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  7.  
  8. void setup (){
  9.     Serial.begin(9600);
  10.     Wire.begin();
  11.     RTC.begin();
  12.  
  13.   if (! RTC.isrunning()){
  14.     Serial.println("RTC is NOT running!");
  15.     // following line sets the RTC to the date & time this sketch was compiled
  16.     RTC.adjust(DateTime(__DATE__, __TIME__));
  17.   }
  18.   }
  19. void loop(){
  20. DateTime agora = RTC.now();
  21. String relogio_data = ("DT: ");
  22. String relogio_hora = ("hr: ");
  23.  
  24. int dia = agora.day();
  25. int mes = agora.month();
  26. int ano = agora.year();
  27.  
  28. relogio_data += dia;
  29. relogio_data += "/";
  30. relogio_data += mes;
  31. relogio_data += "/";
  32. relogio_data += ano;
  33.  
  34. int hora= agora.hour();
  35. int minuto = agora.minute();
  36. int segundo = agora.second();
  37.  
  38. relogio_hora += hora;
  39. relogio_hora += "/";
  40. relogio_hora += minuto;
  41. relogio_hora += "/";
  42. relogio_hora += segundo;
  43.  
  44. lcd.setCursor(0, 0);
  45. lcd.print(relogio_data);
  46. lcd.setCursor(0, 1);
  47. lcd.print(relogio_hora);
  48.  
  49. delay(500);
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement