分享

Arduino LCD+DS3231

#include <Wire.h>
#include <RTClib.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display 
RTC_DS3231 rtc;
char daysOfTheWeek[7][12] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
void setup () {
lcd.init();                      // initialize the lcd 
 lcd.init();
#ifndef ESP8266
 while (!Serial); // for Leonardo/Micro/Zero
#endif
 Serial.begin(9600);
 delay(3000); // wait for console opening
 if (! rtc.begin()) {
   Serial.println("Couldn't find RTC");
   while (1);
 }
 if (rtc.lostPower()) {
   Serial.println("RTC lost power, lets set the time!");
   rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
 }
}
void loop () {
   DateTime now = rtc.now();
   lcd.backlight();
   lcd.setCursor(0,0);
   lcd.print("Time");
   lcd.setCursor(6,0);
   lcd.print(now.year(), DEC);
   lcd.print('/');
   lcd.print(now.month(), DEC);
   lcd.print('/');
   lcd.print(now.day(), DEC);
   lcd.print(' ');
   lcd.setCursor(0,1);
   lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
   lcd.setCursor(8,1);   
   lcd.print(now.hour(), DEC);
   lcd.print(':');
   lcd.print(now.minute(), DEC);
   lcd.print(':');
   lcd.print(now.second(), DEC);
   lcd.println();
   DateTime future (now + TimeSpan(7,12,30,6));
   Serial.println();
   delay(1000);   
}
分類:科技

評論
上一篇
  • 下一篇
  • Arduino LCD+光敏電阻+LED
  • 更多文章
    載入中... 沒有更多了