TA的每日心情 | 开心 2015-10-10 20:28 |
---|
签到天数: 8 天 连续签到: 1 天 [LV.3]偶尔看看II
|
基于1602的自定义字体时钟, 图片及相关信息 :https://github.com/StanleyYake
#include <LiquidCrystal.h>
#include <IRremote.h>
#include <stdio.h> //DS1307
#include <string.h>
#include <DS1307.h>
DS1307 rtc(4, 5);
char yearmonthday[20];
char hourminutesecond[10];
char day[10];
int irReceivePin=2; //IRremote
IRrecv irrecv(irReceivePin);
decode_results results;
#define beta 4090 //remindianzu
LiquidCrystal lcd(3,4,5,6,7,8,9); //displayModel2
byte one[8]={
B11111,B11111,B00000,B11111,B11111,B00000,B11111,B11111};
byte two[8]={
B11111,B11111,B00000,B00000,B00000,B00000,B00000,B00000};
byte three[8]={
B00000,B00000,B00000,B00000,B00000,B00000,B11111,B11111};
byte four[8]={
B11111,B11111,B00000,B00000,B00000,B00000,B11111,B11111};
byte five[8]={
B11111,B11111,B00000,B00000,B00000,B00000,B00000,B11111};
byte six[8]={
B11111,B00000,B00000,B00000,B00000,B00000,B11111,B11111};
byte seven[8]={
B00000,B00000,B00000,B11111,B11111,B00000,B00000,B00000};
byte zero[8]={
B00000,B00000,B00000,B00000,B00000,B00000,B00000,B00000};
void setup()
{
lcd.begin(16,2);
lcd.display();
lcd.createChar(1,one); //displayModel2
lcd.createChar(2,two);
lcd.createChar(3,three);
lcd.createChar(4,four);
lcd.createChar(5,five);
lcd.createChar(6,six);
lcd.createChar(7,seven);
lcd.createChar(8,zero);
irrecv.enableIRIn(); //IRremote
Serial.begin(9600);
}
void loop()
{
int Model;
if(irrecv.decode(&results))
{
Serial.println(results.value);
long remote=results.value;
if(remote==16597183)
{
Model=2;
lcd.clear();
}
else if(remote==16597183)
{
Model=2;
lcd.clear();
}
irrecv.resume();
}
else
{
displayModel1();
}
while(Model==1)
{
displayModel1();
if(irrecv.decode(&results))
{
Serial.println(results.value);
long remote=results.value;
if(remote==16580863)
{
Model=1;
lcd.clear();
}
else if(remote==16597183)
{
Model=2;
lcd.clear();
}
irrecv.resume();
}
}
while(Model==2)
{
displayModel2();
if(irrecv.decode(&results))
{
Serial.println(results.value);
long remote=results.value;
if(remote==16580863)
{
Model=1;
lcd.clear();
}
else if(remote==16597183)
{
Model=2;
lcd.clear();
}
irrecv.resume();
}
}
}
void displayModel1()
{
timeandtempDisplay();
}
void timeandtempDisplay()
{
Time t=rtc.time();
memset(day,0, sizeof(day));
switch (t.day)
{
case 1:
strcpy(day, "Sun");
break;
case 2:
strcpy(day, "Mon");
break;
case 3:
strcpy(day, "Tue");
break;
case 4:
strcpy(day, "Wed");
break;
case 5:
strcpy(day, "Thr");
break;
case 6:
strcpy(day, "Fri");
break;
case 7:
strcpy(day, "Sat");
break;
}
snprintf(yearmonthday, sizeof(yearmonthday), "%04d/%02d/%02d",t.yr,t.mon,t.date);
snprintf(hourminutesecond,sizeof(hourminutesecond),"%02d:%02d:%02d",t.hr, t.min, t.sec);
lcd.setCursor(0,0);
lcd.print(yearmonthday);
lcd.setCursor(13,0);
lcd.print(day);
lcd.setCursor(0,1);
tempDisplay();
lcd.setCursor(8,1);
lcd.print(hourminutesecond);
}
void tempDisplay()
{
int t=analogRead(A0);
float temp=beta/(log((1023.0/t)-1.0)+(beta/298.0))-273.0;
int temperature=temp;
lcd.print(temperature);
lcd.write(0xDF);
lcd.print("C");
}
void displayModel2()
{
minuteDisplay();
hourDisplay();
}
void hourDisplay()
{
Time t=rtc.time();
int hour=t.hr;
if(hour<12&hour>0)
{
int houra=hour/10;
int hourb=hour%10;
if(hour>0&hour<10)
{
numberDisplay(10,-1,0);
numberDisplay(hour,3,0);
}
else
{
numberDisplay(houra,-1,0);
numberDisplay(hourb,3,0);
}
amDisplay();
}
else if(hour>12&hour<24)
{
hour=hour-12;
int houra=hour/10;
int hourb=hour%10;
if(hour>0&hour<10)
{
numberDisplay(10,-1,0);
numberDisplay(hour,3,0);
}
else
{
numberDisplay(houra,-1,0);
numberDisplay(hourb,3,0);
}
pmDisplay();
}
else if(hour<1)
{
numberDisplay(1,-1,0);
numberDisplay(2,3,0);
amDisplay();
}
else if (hour==12)
{
numberDisplay(0,3,0);
pmDisplay();
}
}
void minuteDisplay()
{
Time t=rtc.time();
int minute=t.min;
int minutea=minute/10;
int minuteb=minute%10;
if(minute>=10)
{
numberDisplay(minutea,9,0);
numberDisplay(minuteb,13,0);
}
else
{
numberDisplay(0,9,0);
numberDisplay(minuteb,13,0);
}
}
void numberDisplay(int i,int cols,int rows)
{
switch(i)
{
case 0:
zeroDisplay(cols,rows);
break;
case 1:
oneDisplay(cols,rows);
break;
case 2:
twoDisplay(cols,rows);
break;
case 3:
threeDisplay(cols,rows);
break;
case 4:
fourDisplay(cols,rows);
break;
case 5:
fiveDisplay(cols,rows);
break;
case 6:
sixDisplay(cols,rows);
break;
case 7:
sevenDisplay(cols,rows);
break;
case 8:
eightDisplay(cols,rows);
break;
case 9:
nineDisplay(cols,rows);
break;
case 10:
nullDisplay(cols,rows);
break;
}
}
void zeroDisplay(int col, int row)
{
lcd.setCursor(col,row);
lcd.write(1);
lcd.setCursor(col+1,row);
lcd.write(2);
lcd.setCursor(col+2,row);
lcd.write(1);
lcd.setCursor(col,row+1);
lcd.write(1);
lcd.setCursor(col+1,row+1);
lcd.write(3);
lcd.setCursor(col+2,row+1);
lcd.write(1);
}
void oneDisplay(int col, int row)
{
lcd.setCursor(col,row);
lcd.write(8);
lcd.setCursor(col+1,row);
lcd.write(1);
lcd.setCursor(col+2,row);
lcd.write(8);
lcd.setCursor(col,row+1);
lcd.write(8);
lcd.setCursor(col+1,row+1);
lcd.write(1);
lcd.setCursor(col+2,row+1);
lcd.write(8);
}
void twoDisplay(int col, int row)
{
lcd.setCursor(col,row);
lcd.write(2);
lcd.setCursor(col+1,row);
lcd.write(2);
lcd.setCursor(col+2,row);
lcd.write(1);
lcd.setCursor(col,row+1);
lcd.write(1);
lcd.setCursor(col+1,row+1);
lcd.write(4);
lcd.setCursor(col+2,row+1);
lcd.write(4);
}
void threeDisplay(int col, int row)
{
lcd.setCursor(col,row);
lcd.write(4);
lcd.setCursor(col+1,row);
lcd.write(4);
lcd.setCursor(col+2,row);
lcd.write(1);
lcd.setCursor(col,row+1);
lcd.write(3);
lcd.setCursor(col+1,row+1);
lcd.write(3);
lcd.setCursor(col+2,row+1);
lcd.write(1);
}
void fourDisplay(int col, int row)
{
lcd.setCursor(col,row);
lcd.write(1);
lcd.setCursor(col+1,row);
lcd.write(8);
lcd.setCursor(col+2,row);
lcd.write(1);
lcd.setCursor(col,row+1);
lcd.write(2);
lcd.setCursor(col+1,row+1);
lcd.write(2);
lcd.setCursor(col+2,row+1);
lcd.write(1);
}
void fiveDisplay(int col, int row)
{
lcd.setCursor(col,row);
lcd.write(1);
lcd.setCursor(col+1,row);
lcd.write(4);
lcd.setCursor(col+2,row);
lcd.write(4);
lcd.setCursor(col,row+1);
lcd.write(3);
lcd.setCursor(col+1,row+1);
lcd.write(3);
lcd.setCursor(col+2,row+1);
lcd.write(1);
}
void sixDisplay(int col, int row)
{
lcd.setCursor(col,row);
lcd.write(1);
lcd.setCursor(col+1,row);
lcd.write(2);
lcd.setCursor(col+2,row);
lcd.write(2);
lcd.setCursor(col,row+1);
lcd.write(1);
lcd.setCursor(col+1,row+1);
lcd.write(4);
lcd.setCursor(col+2,row+1);
lcd.write(1);
}
void sevenDisplay(int col, int row)
{
lcd.setCursor(col,row);
lcd.write(2);
lcd.setCursor(col+1,row);
lcd.write(2);
lcd.setCursor(col+2,row);
lcd.write(1);
lcd.setCursor(col,row+1);
lcd.write(8);
lcd.setCursor(col+1,row+1);
lcd.write(8);
lcd.setCursor(col+2,row+1);
lcd.write(1);
}
void eightDisplay(int col, int row)
{
lcd.setCursor(col,row);
lcd.write(1);
lcd.setCursor(col+1,row);
lcd.write(5);
lcd.setCursor(col+2,row);
lcd.write(1);
lcd.setCursor(col,row+1);
lcd.write(1);
lcd.setCursor(col+1,row+1);
lcd.write(6);
lcd.setCursor(col+2,row+1);
lcd.write(1);
}
void nineDisplay(int col, int row)
{
lcd.setCursor(col,row);
lcd.write(1);
lcd.setCursor(col+1,row);
lcd.write(4);
lcd.setCursor(col+2,row);
lcd.write(1);
lcd.setCursor(col,row+1);
lcd.write(3);
lcd.setCursor(col+1,row+1);
lcd.write(3);
lcd.setCursor(col+2,row+1);
lcd.write(1);
}
void nullDisplay(int col,int row)
{
lcd.setCursor(col,row);
lcd.write(8);
lcd.setCursor(col+1,row);
lcd.write(8);
lcd.setCursor(col+2,row);
lcd.write(8);
lcd.setCursor(col,row+1);
lcd.write(8);
lcd.setCursor(col+1,row+1);
lcd.write(8);
lcd.setCursor(col+2,row+1);
lcd.write(8);
}
void amDisplay()
{
lcd.setCursor(7,0);
lcd.print('a');
lcd.setCursor(7,1);
lcd.print('m');
delay(500);
lcd.setCursor(7,0);
lcd.write(8);
lcd.setCursor(7,1);
lcd.write(8);
delay(500);
}
void pmDisplay()
{
lcd.setCursor(7,0);
lcd.print('p');
lcd.setCursor(7,1);
lcd.print('m');
delay(500);
lcd.setCursor(7,0);
lcd.write(8);
lcd.setCursor(7,1);
lcd.write(8);
delay(500);
}
|
|