|
#include <Wire.h>
#include <DS3231.h>
#include <LiquidCrystal.h>
DS3231 Clock;
bool h12,PM,Century=false;
byte year,month,date,DoW,hour,minute,second;
LiquidCrystal lcd(12,11,2,3,4,5,6,7,8,9,10);
void setup() {
Wire.begin();
Clock.setSecond(50);
Clock.setMinute(59);
Clock.setHour(11);
Clock.setDoW(5);
Clock.setDate(31);
Clock.setMonth(5);
Clock.setYear(13);
}
void Pritime()
{
int second,minute,hour,date,month,year,dow,temperature;
second=Clock.getSecond();
minute=Clock.getMinute();
hour=Clock.getHour(h12,PM);
date=Clock.getDate();
month=Clock.getMonth(Century);
year=Clock.getYear();
dow=Clock.getDoW();
temperature=Clock.getTemperature();
lcd.setCursor(0,0);
lcd.print("20");
if(year>=10)
{
lcd.print(year,DEC);
}
else
{
lcd.print("0");
lcd.print(year,DEC);
}
lcd.print('-');
lcd.setCursor(5,0);
if (month>=10)
{
lcd.print(month,DEC);
}
else
{
lcd.print("0");
lcd.print(month,DEC);
}
lcd.print('-');
lcd.setCursor(8,0);
if(date>=10)
{
lcd.print(date,DEC);
}
else
{
lcd.print("0");
lcd.print(date,DEC);
}
lcd.setCursor(11,0);
switch (dow)
{
case 1:
lcd.print("Mon");
break;
case2:
lcd.print("Tue");
break;
case 3:
lcd.print("Wed");
break;
case 4:
lcd.print("Thu");
break;
case 5:
lcd.print("Fri");
break;
case 6:
lcd.print("Sat");
break;
case 7:
lcd.print("Sun");
break;
}
lcd.LCD_SET_XY(1,0);
if (hour>=10)
{
lcd.print(hour,DEC);
}
else
{
lcd.print("0");
lcd.print(hour,DEC);
}
lcd.print(':');
lcd.LCD_SET_XY(1,3);
if(minute>=10)
{
lcd.print(minute,DEC);
}
else
{
lcd.print("0");
lcd.print(minute,DEC);
}
lcd.print(':');
lcd.LCD_SET_XY(1,6);
if(second>=10)
{
lcd.print(second,DEC);
}
else
{
lcd.print("0");
lcd.print(second,DEC);
}
lcd.LCD_SET_XY(1,12);
lcd.print(temperature);
lcd.write(0xdf);
lcd.print("C");
}
void Tictime() {
lcd.LCD_SET_XY(1,2);
lcd.print(' ');
lcd.LCD_SET_XY(1,5);//这里出现了一点小问题为什么显示“'class LiquidCrystal' has no member named 'LCD_SET_XY'”
lcd.print(' ');
}
void loop()
{
unsigned long Rt=millis()%1000;
if(Rt<500)
{
Pritime();
}
else
{
Tictime();
}
}
刚刚接触ARDUINO还不太上手,谢谢大神指导
|
|