Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal_I2C.h>
- #include <DS3231.h>
- #include <Wire.h>
- LiquidCrystal_I2C lcd(0x38, 2, 1, 0, 7, 6, 5, 4, 3, POSITIVE);
- DS3231 rtc(SDA, SCL);
- Time t;
- //-------------------------------------
- void setup() {
- Serial.begin(9600);
- rtc.begin();
- lcd.begin(16, 2);
- //The following lines can be uncommented to set the date and time
- //rtc.setDOW(WEDNESDAY); // Set Day-of-Week to SUNDAY
- //rtc.setTime(8, 33,0 ); // Set the time to 12:00:00 (24hr format)
- //rtc.setDate(4, 10, 2016); // Set the date to January 1st, 2014
- }
- //--------------------------------------------
- void loop()
- {
- tempo();
- }
- //--------------------------------------
- void tempo()
- {
- // Get data from the DS3231
- t = rtc.getTime();
- // Send date over serial connection
- //Serial.print("Today is the ");
- if (t.date < 10) {
- lcd.setCursor(0, 0);
- lcd.print("0");
- lcd.print(t.date, DEC);
- }
- if (t.date >= 10) {
- lcd.setCursor(0, 0);
- lcd.print(t.date, DEC);
- }
- lcd.print("-");
- lcd.print(rtc.getMonthStr(FORMAT_SHORT));
- lcd.print("-");
- lcd.print(t.year, DEC);
- // Send Day-of-Week and time
- //Serial.print(t.dow, DEC);
- if (t.hour < 10) {
- lcd.setCursor(0, 1);
- lcd.print("0");
- lcd.print(t.hour, DEC);
- }
- if (t.hour >= 10) {
- lcd.setCursor(0, 1);
- lcd.print(t.hour, DEC);
- }
- lcd.print(":");
- if (t.min < 10) {
- lcd.setCursor(3, 1);
- lcd.print("0");
- lcd.print(t.min, DEC);
- }
- if (t.min >= 10) {
- lcd.setCursor(3, 1);
- lcd.print(t.min, DEC);
- }
- lcd.print(":");
- if (t.sec < 10) {
- lcd.setCursor(6, 1);
- lcd.print("0");
- lcd.print(t.sec, DEC);
- }
- if (t.sec >= 10) {
- lcd.setCursor(6, 1);
- lcd.print(t.sec, DEC);
- }
- lcd.setCursor(8, 1);
- lcd.print(" ");
- lcd.print(rtc.getTemp());
- lcd.println(" C");
- // Wait one second before repeating :)
- delay (1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement