#include <virtuabotixRTC.h> //Library for RTC DS1302
#include <DallasTemperature.h> //Library for Temp Sensor
#include <OneWire.h>
#include <LiquidCrystal.h> //LCD library
#define ONE_WIRE_BUS 7 // Data wire is connected to the Arduino digital pin 7
virtuabotixRTC myRTC(A0, A1, A2); //Wiring configuration
OneWire oneWire(ONE_WIRE_BUS);// Setup a oneWire instance to communicate with any OneWire devices
DallasTemperature sensors(&oneWire);// Pass our oneWire reference to Dallas Temperature sensor
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //setup of LCD display
//Creation of the ° symbol
byte celsius[8] =
{
0b01110,
0b01010,
0b01110,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000
};
void setup() {
sensors.begin(); // Start up the library
lcd.createChar(0, celsius);
lcd.begin(16, 2); //initialize library
//myRTC.setDS1302Time(0, 18, 17, 5, 24, 6, 2021); //initialize date and time, used only once at the beginning
//second,minute,hour,dayOfTheWeek,day,month,year
//dayOfTheWeek means 1 for Sunday, 2 for Monday etc... if you want to display it, not used here
}
void loop() {
//-----Temperature-----
sensors.requestTemperatures(); //reads the temperature
lcd.setCursor(0, 0);
lcd.print(sensors.getTempCByIndex(0)); //shows temperature in Celsius with 2 decimals
lcd.setCursor(4, 0); //position of the 2nd decimal
lcd.write(byte(0)); //writes ° on the 2nd decimal that I don't want
lcd.print("C ");
//-----Clock-----
myRTC.updateTime();
lcd.print(myRTC.hours);
lcd.print(":");
lcd.print(myRTC.minutes);
lcd.print(":");
lcd.print(myRTC.seconds);
lcd.setCursor(0, 1);
lcd.print(myRTC.dayofmonth);
lcd.print("/");
lcd.print(myRTC.month);
lcd.print("/");
lcd.print(myRTC.year);
delay(350);
if (myRTC.minutes == 59 && myRTC.seconds == 59) { //correction of the display errors at the end of a hour
lcd.setCursor(10, 0);
lcd.print(" ");
lcd.setCursor(13, 0);
lcd.print(" ");
lcd.print(" ");
}
if (myRTC.seconds == 59) { //correction of the display errors at the end of a minute
lcd.setCursor(14, 0);
lcd.print(" ");
}
}
Comments