before |
after |
#include
#include "RTClib.h"
#include
RTC_DS1307 RTC;
LiquidCrystal lcd(6, 7, 8, 9, 14, 15);
void setup () {
Serial.begin(9600);
Wire.begin();
RTC.begin();
if (!RTC.isrunning()) {
Serial.println("RTC is NOT running!");
RTC.adjust(DateTime(__DATE__, __TIME__));
}
lcd.begin(16, 2);
}
void loop () {
DateTime now = RTC.now();
lcd.clear();
lcd.setCursor(4, 0);
lcd.print(format(now.hour()));
lcd.print(':');
lcd.print(format(now.minute()));
lcd.print(':');
lcd.print(format(now.second()));
lcd.setCursor(3, 1);
lcd.print(format(now.day()));
lcd.print('/');
lcd.print(format(now.month()));
lcd.print('/');
lcd.print(now.year(), DEC);
delay(1000);
}
String format(int num) {
String addZero = "0";
String d = "";
if (String(num).length() < 2){
return addZero + String(num);
}
return String(num);
}
0 comments:
Postar um comentário