第一次发帖,二进制时钟
一直以来,都是在本论坛学习,至今一直没做出过东西,废话不多说了,看见其他创客做了二进制时钟,自己也想做个,
没想到慢慢就做成了,虽然代码都是组装的,但是以后一定要自己写代码
硬件ds1307
uno
max7219点阵模块
UNO与ds1307连线
SDA(A4)-SDA
SCK(A5)-SCK
max7219模块与UNO连接
10-CS
11-CLK
12-DIN
file:///C:\Users\耀凯\Documents\Tencent Files\1643453868\Image\C2C\AF45EEBC14BB2D5F6029EA75968BCBC3.jpgfile:///C:\Users\耀凯\Documents\Tencent Files\1643453868\Image\C2C\AF45EEBC14BB2D5F6029EA75968BCBC3.jpg
向时钟芯片写时间2016.326.20.56
/****************************************************************************/
// 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"
DS1307 clock;//define a object of DS1307 class
void setup()
{
Serial.begin(9600);
clock.begin();
clock.fillByYMD(2016,3,26);//Jan 19,2013
clock.fillByHMS(20,56,30);//15:28 30"
clock.fillDayOfWeek(SAT);//Saturday
clock.setTime();//write time to the RTC chip
}
void loop()
{
}
/*printTime();
}
/*Function: Display time on the serial monitor*/
void printTime()
{
clock.getTime();
Serial.print(clock.hour);
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(" ");*/
}
再将时间读出来即可
/****************************************************************************/
//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 朋友你好,请问arduino uno与max7219如何连接
max7219模块与UNO连接 10-CS 11-CLK 12-DIN 我用的是模块化的点阵
页:
[1]