Advertisement
RuiViana

Relogio_RTC_Temperatura

Oct 5th, 2016
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.91 KB | None | 0 0
  1.  
  2. #include <LiquidCrystal_I2C.h>
  3. #include <DS3231.h>
  4. #include <Wire.h>
  5.  
  6.  
  7. LiquidCrystal_I2C lcd(0x38,  2, 1, 0, 7, 6, 5, 4, 3, POSITIVE);
  8. DS3231  rtc(SDA, SCL);
  9. Time  t;
  10.  
  11. //-------------------------------------
  12. void setup() {
  13.   Serial.begin(9600);
  14.   rtc.begin();
  15.   lcd.begin(16, 2);
  16.   //The following lines can be uncommented to set the date and time
  17.   //rtc.setDOW(WEDNESDAY);     // Set Day-of-Week to SUNDAY
  18.   //rtc.setTime(8, 33,0 );     // Set the time to 12:00:00 (24hr format)
  19.   //rtc.setDate(4, 10, 2016);   // Set the date to January 1st, 2014
  20. }
  21. //--------------------------------------------
  22. void loop()
  23. {
  24.  
  25. tempo();
  26. }
  27. //--------------------------------------
  28. void tempo()
  29. {
  30.   // Get data from the DS3231
  31.   t = rtc.getTime();
  32.   // Send date over serial connection
  33.   //Serial.print("Today is the ");
  34.  
  35.   if (t.date < 10) {
  36.     lcd.setCursor(0, 0);
  37.     lcd.print("0");
  38.     lcd.print(t.date, DEC);
  39.   }
  40.   if (t.date >= 10) {
  41.     lcd.setCursor(0, 0);
  42.     lcd.print(t.date, DEC);
  43.   }
  44.   lcd.print("-");
  45.   lcd.print(rtc.getMonthStr(FORMAT_SHORT));
  46.   lcd.print("-");
  47.   lcd.print(t.year, DEC);
  48.  
  49.   // Send Day-of-Week and time
  50.   //Serial.print(t.dow, DEC);
  51.   if (t.hour < 10) {
  52.     lcd.setCursor(0, 1);
  53.     lcd.print("0");
  54.     lcd.print(t.hour, DEC);
  55.   }
  56.   if (t.hour >= 10) {
  57.     lcd.setCursor(0, 1);
  58.     lcd.print(t.hour, DEC);
  59.   }
  60.   lcd.print(":");
  61.   if (t.min < 10) {
  62.     lcd.setCursor(3, 1);
  63.     lcd.print("0");
  64.     lcd.print(t.min, DEC);
  65.   }
  66.   if (t.min >= 10) {
  67.     lcd.setCursor(3, 1);
  68.     lcd.print(t.min, DEC);
  69.   }
  70.  
  71.   lcd.print(":");
  72.   if (t.sec < 10) {
  73.     lcd.setCursor(6, 1);
  74.     lcd.print("0");
  75.     lcd.print(t.sec, DEC);
  76.   }
  77.   if (t.sec >= 10) {
  78.     lcd.setCursor(6, 1);
  79.     lcd.print(t.sec, DEC);
  80.   }
  81.   lcd.setCursor(8, 1);
  82.   lcd.print(" ");
  83.   lcd.print(rtc.getTemp());
  84.   lcd.println(" C");
  85.  
  86.   // Wait one second before repeating :)
  87.   delay (1000);
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement