【菜鸟的Arduino学习之路】个人superclock时钟V0.1版

但丁 于 2012-9-13 20:54 编辑



学习Arduino有一个月左右了吧,今天尝试做了个小时钟,效果还不是很好,但是鉴于马上要出国读书了,还是想写一篇帖子,也算是交个作业以及表达一下对极客工坊这么好的学习之地表示感谢吧!

关于时钟性能的改进等日后有空了再进一步更新~~~话说自己大爱做时钟



元件清单:1.热敏电阻或LM35温度传感器(自己用的是热敏电阻,便宜点哇)

2.DS1302时钟模块

3.红外遥控器及红外一体接收头

4.1602液晶屏







好了,废话不多说,上图,上视频~~

1DSC01822.jpg

2012-9-13 20:43 上传
(173.76 KB)


1DSC01824.jpg

2012-9-13 20:43 上传
(169.59 KB)


1DSC01826.jpg

2012-9-13 20:43 上传
(183.91 KB)


1DSC01823.jpg

2012-9-13 20:43 上传
(233.47 KB)













接下来是代码,写得有点乱,喜欢的朋友可以尝试一下:

ARDUINO 代码复制打印

#include <LiquidCrystal.h>#include <IRremote.h>#include <stdio.h>      //DS1302#include <string.h>#include <DS1302.h>uint8_t CE_PIN = 12;uint8_t IO_PIN = 11;uint8_t SCLK_PIN = 10;DS1302 rtc(CE_PIN,IO_PIN,SCLK_PIN);char yearmonthday[20];char hourminutesecond[10];char day[10];int irReceivePin=2;       //IRremoteIRrecv irrecv(irReceivePin);decode_results results;#define beta 4090       //remindianzuLiquidCrystal lcd(3,4,5,6,7,8,9);  //displayModel2byte 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);     //displayModel2lcd.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();    //IRremoteSerial.begin(9600);}void loop(){ int Model; 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(); }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>





基本上我的superclock的V0.1版本就是这个样子了,当然还存在很多问题,等日后有空了果断再更新一下,只因我个人大爱时钟,希望能做出更加个性化而且功能完善的时钟吧,先mark下日后需要改进的地方:
1.遥控设定时间
2.闹钟设定


PS:视频中也提到了Remote的库和Arduino本身的tone函数存在冲突,暂时功力还不够深厚,等日后好好研究一下再改进!
鄙人不才,还望各位大神指点!另真心感谢极客工坊提供这么好的学习平台!
via - 极客工坊

标签: Arduino教程