Hey guys!
I have my LCD clock and sensor temperature working fine.
However, I don't know how the DS1307 RTC really works, so I have a couples questions:
1 - If I increase the day by one, does the weekday also increases by one?
2 - Does this RTC knows when a month has 28/29/30/31 days?
3 - Does the RTC knows when the year is leap (bissextile).
4 - Finally, if all the above are true, do I need to add anything else on my code so it works like a real calendar/clock?
Regarding the manual setup up of the clock... How can I do it? I am thinking in 2 pushbuttons but how do I code it?
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>
#include <LiquidCrystal.h>
#include "RTClib.h"
RTC_DS1307 RTC;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
byte graus[8] = {
0b01110,
0b10001,
0b10001,
0b01110,
0b00000,
0b00000,
0b00000,
0b00000
};
int pin=0; // analog pin
long int temp=0, Vin=0, k=0;
long double samples[20];
long double min = (-424.0/6.25);
void setup ()
{
Serial.begin(57600);
Wire.begin();
RTC.begin();
lcd.begin(16, 2);
lcd.createChar(0, graus);
analogReference(INTERNAL);
if (! RTC.isrunning())
{
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
}
void loop () {
DateTime now = RTC.now();
lcd.home();
if (now.hour() < 10)
{
lcd.print('0');
lcd.print(now.hour(), DEC);
lcd.print(':');
}
else
{
lcd.print(now.hour(), DEC);
lcd.print(':');
}
if (now.minute() < 10)
{
lcd.print('0');
lcd.print(now.minute(), DEC);
lcd.print(':');
}
else
{
lcd.print(now.minute(), DEC);
lcd.print(':');
}
if (now.second() < 10)
{
lcd.print('0');
lcd.print(now.second(), DEC);
}
else {
lcd.print(now.second(), DEC);
}
lcd.setCursor(0,1);
if (now.day() < 10)
{
lcd.print('0');
lcd.print(now.day(), DEC);
lcd.print('/');
}
else
{
lcd.print(now.day(), DEC);
lcd.print('/');
}
if (now.month() < 10)
{
lcd.print('0');
lcd.print(now.month(), DEC);
lcd.print('/');
}
else
{
lcd.print(now.month(), DEC);
lcd.print('/');
}
lcd.print(now.year(), DEC);
lcd.setCursor(12, 1);
if (now.dayOfWeek() == 0)
lcd.print("Sun");
if (now.dayOfWeek() == 1)
lcd.print("Mon");
if (now.dayOfWeek() == 2)
lcd.print("Tue");
if (now.dayOfWeek() == 3)
lcd.print("Wed");
if (now.dayOfWeek() == 4)
lcd.print("Thu");
if (now.dayOfWeek() == 5)
lcd.print("Fri");
if (now.dayOfWeek() == 6)
lcd.print("Sat");
for(k=0 ; k<=19 ; k++)
{
samples[k] = (analogRead(pin)*(1100/1088));
Vin = Vin + samples[k];
delay(2);
}
temp = (Vin/20 /1024.0 * 1088.0 / 6.25) + min;
if (temp >=0 & temp <=9)
{
lcd.setCursor(11, 0);
lcd.print(" ");
lcd.print(temp, DEC);
}
if (temp >=10 & temp <=99)
{
lcd.setCursor(11, 0);
lcd.print(" ");
lcd.print(temp, DEC);
}
if (temp >=100 & temp <=150)
{
lcd.setCursor(11, 0);
lcd.print(temp, DEC);
}
if (temp >=-9 & temp <=-1)
{
lcd.setCursor(11, 0);
lcd.print(" ");
lcd.print(temp, DEC);
}
if (temp >=-99 & temp <=-10)
{
lcd.setCursor(11, 0);
lcd.print(temp, DEC);
}
lcd.setCursor(14, 0);
lcd.write((uint8_t)0);
lcd.print("C");
Vin=0;
temp = 0;
k=0;
delay(200);
}