|
楼主 |
发表于 2016-3-26 21:40
|
显示全部楼层
- 再将时间读出来即可
- /****************************************************************************/
- // Function: Set time and get the time from RTC chip(DS1307) and display
- // it on the serial monitor.
- // Hardware: RTC by Catalex
- // Arduino IDE: Arduino-1.0
- // Author: Fred.Chu
- // Date: April 19,2013
- // Version: v1.0
- // by catalex.taobao.com
- //
- // This library is free software; you can redistribute it and/or
- // modify it under the terms of the GNU Lesser General Public
- // License as published by the Free Software Foundation; either
- // version 2.1 of the License, or (at your option) any later version.
- //
- // This library is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- // Lesser General Public License for more details.
- //
- // You should have received a copy of the GNU Lesser General Public
- // License along with this library; if not, write to the Free Software
- // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- //
- /****************************************************************************/
- #include <Wire.h>
- #include "DS1307.h"
- #include <LedControl.h>
- DS1307 clock;//define a object of DS1307 class
- LedControl lc=LedControl(12,11,10,1); //实例化一个LedControl类的对象
- void setup()
- {
- Serial.begin(9600);
- clock.begin();
- lc.setIntensity(0,3);
- lc.shutdown(0,false);
- lc.clearDisplay(0);
- }
- void loop()
- {
- clock.getTime();
- // int i=clock.second%10;
- //int j=clock.second/10;
- // int k=clock.minute%10;
- // int q=clock.minute/10;
- lc.setColumn(0,7,byte(clock.second%10)); //在4位数码管的第0位(左数第一位)显示秒的个位
- lc.setColumn(0,6,byte(clock.second/10)); //在4位数码管的第1位(左数第二位)显示秒的十位
- lc.setColumn(0,4,byte(clock.minute%10)); //在4位数码管的第2位(左数第三位)显示分的个位
- lc.setColumn(0,3,byte(clock.minute/10)); //在4位数码管的第3位(左数第四位)显示分的十位
- lc.setColumn(0,1,byte(clock.hour%10));//时的个位
- lc.setColumn(0,0,byte(clock.hour/10));//时的十位
- //Serial.print(clock.hour, DEC);
- // printTime();
- }
- /*Function: Display time on the serial monitor*/
- /*void printTime()
- {
- clock.getTime();
- Serial.print(clock.hour, DEC);
- Serial.print(":");
- Serial.print(clock.minute, DEC);
- Serial.print(":");
- Serial.print(clock.second, DEC);
- Serial.print(" ");
- Serial.print(clock.month, DEC);
- Serial.print("/");
- Serial.print(clock.dayOfMonth, DEC);
- Serial.print("/");
- Serial.print(clock.year+2000, DEC);
- Serial.print(" ");
- switch (clock.dayOfWeek)// Friendly printout the weekday
- {
- case MON:
- Serial.print("MON");
- break;
- case TUE:
- Serial.print("TUE");
- break;
- case WED:
- Serial.print("WED");
- break;
- case THU:
- Serial.print("THU");
- break;
- case FRI:
- Serial.print("FRI");
- break;
- case SAT:
- Serial.print("SAT");
- break;
- case SUN:
- Serial.print("SUN");
- break;
- }
- Serial.println(" ");
- }*/
复制代码
LedControl库
ds1307库我忘了链接在哪了,谁需要联系我
http://playground.arduino.cc/Main/LedControl#Source |
|