这篇文章是自己打算做一个LED点阵时钟记录学习进度的,刚完成第一次点亮MAX7219四合一模块,所以先做好学习记录。
Arduino nano | DS3231 |
---|---|
3.3v | vcc |
GND | GND |
A3 | SCL |
A4 | SCL |
Arduino nano | Max7219 |
---|---|
5V | vcc |
GND | GND |
11 | DIN |
9 | CS |
13 | CLK |
代码部分参考的mixly,Mixly官网
所需要的库文件在文章末尾有链接,有需要的自己下载就好
#include
#include
#include
#include
#include
SoftwareWire myWire(A3,A4);//DS3231引脚sda-a3 scl-a4
RtcDS3231<SoftwareWire> Rtc(myWire);
Max72xxPanel myMatrix = Max72xxPanel(9,4,1);//max7219引脚din-11 cs-9 clk-13
uint8_t LEDArray[8];
unsigned char const LedArray0[8] PROGMEM ={
0x7e,0x66,0x66,0x66,0x66,0x66,0x66,0x7e};
unsigned char const LedArray1[8] PROGMEM ={
0x7e,0x18,0x18,0x18,0x18,0x18,0x1c,0x18};
unsigned char const LedArray2[8] PROGMEM ={
0x7e,0x06,0x06,0x7e,0x60,0x60,0x60,0x7e};
unsigned char const LedArray3[8] PROGMEM ={
0x7e,0x60,0x60,0x7e,0x60,0x60,0x60,0x7e};
unsigned char const LedArray4[8] PROGMEM ={
0x60,0x60,0x60,0x7e,0x66,0x66,0x66,0x66};
unsigned char const LedArray5[8] PROGMEM ={
0x7e,0x60,0x60,0x7e,0x06,0x06,0x06,0x7e};
unsigned char const LedArray6[8] PROGMEM ={
0x7e,0x66,0x66,0x7e,0x06,0x06,0x06,0x7e};
unsigned char const LedArray7[8] PROGMEM ={
0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x7e};
unsigned char const LedArray8[8] PROGMEM ={
0x7e,0x66,0x66,0x7e,0x66,0x66,0x66,0x7e};
unsigned char const LedArray9[8] PROGMEM ={
0x7e,0x60,0x60,0x7e,0x66,0x66,0x66,0x7e};
void setup(){
Rtc.Begin();
Rtc.SetIsRunning(true);
//Rtc.SetDateTime(RtcDateTime(__DATE__, __TIME__));//获取系统时间
}
void loop(){
//Rtc.SetDateTime(RtcDateTime("Jan/01/2020", "08:00:00"));
myMatrix.setIntensity(0);//点阵亮度调节数值0-5
myMatrix.setRotation(0,1);//点阵显示方向数值1(270度)
myMatrix.setRotation(1,1);
myMatrix.setRotation(2,1);
myMatrix.setRotation(3,1);
int year = Rtc.GetDateTime().Year();
int mon = Rtc.GetDateTime().Month();
int day = Rtc.GetDateTime().Day();
int hour = Rtc.GetDateTime().Hour();
int min = Rtc.GetDateTime().Minute();
int a=hour/10;
int b=hour%10;
if(a==0){
memcpy_P(&LEDArray, &LedArray0, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=0*8; index_j<0*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
}
if(a==1){
memcpy_P(&LEDArray, &LedArray1, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=0*8; index_j<0*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
}
if(a==2){
memcpy_P(&LEDArray, &LedArray2, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=0*8; index_j<0*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
}
if(b==0){
memcpy_P(&LEDArray, &LedArray0, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=1*8; index_j<1*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
}
if(b==1){
memcpy_P(&LEDArray, &LedArray1, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=1*8; index_j<1*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
}
if(b==2){
memcpy_P(&LEDArray, &LedArray2, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=1*8; index_j<1*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
}
if(b==3){
memcpy_P(&LEDArray, &LedArray3, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=1*8; index_j<1*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
}
if(b==4){
memcpy_P(&LEDArray, &LedArray4, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=1*8; index_j<1*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
}
if(b==5){
memcpy_P(&LEDArray, &LedArray5, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=1*8; index_j<1*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
}
if(b==6){
memcpy_P(&LEDArray, &LedArray6, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=1*8; index_j<1*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
}
if(b==7){
memcpy_P(&LEDArray, &LedArray7, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=1*8; index_j<1*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
}
if(b==8){
memcpy_P(&LEDArray, &LedArray8, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=1*8; index_j<1*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
}
if(b==9){
memcpy_P(&LEDArray, &LedArray9, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=1*8; index_j<1*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
}
//*********************************************************************
int c=min/10;
int d=min%10;
if(c==0){
memcpy_P(&LEDArray, &LedArray0, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=2*8; index_j<2*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
}
if(c==1){
memcpy_P(&LEDArray, &LedArray1, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=2*8; index_j<2*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
}
if(c==2){
memcpy_P(&LEDArray, &LedArray2, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=2*8; index_j<2*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
}
if(c==3){
memcpy_P(&LEDArray, &LedArray3, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=2*8; index_j<2*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
}
if(c==4){
memcpy_P(&LEDArray, &LedArray4, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=2*8; index_j<2*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
}
if(c==5){
memcpy_P(&LEDArray, &LedArray5, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=2*8; index_j<2*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
}
//*****************************************************************
if(d==0){
memcpy_P(&LEDArray, &LedArray0, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=3*8; index_j<3*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
}
if(d==1){
memcpy_P(&LEDArray, &LedArray1, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=3*8; index_j<3*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
}
if(d==2){
memcpy_P(&LEDArray, &LedArray2, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=3*8; index_j<3*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
}
if(d==3){
memcpy_P(&LEDArray, &LedArray3, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=3*8; index_j<3*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
}
if(d==4){
memcpy_P(&LEDArray, &LedArray4, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=3*8; index_j<3*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
}
if(d==5){
memcpy_P(&LEDArray, &LedArray5, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=3*8; index_j<3*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
}
if(d==6){
memcpy_P(&LEDArray, &LedArray6, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=3*8; index_j<3*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
}
if(d==7){
memcpy_P(&LEDArray, &LedArray7, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=3*8; index_j<3*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
}
if(d==8){
memcpy_P(&LEDArray, &LedArray8, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=3*8; index_j<3*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
}
if(d==9){
memcpy_P(&LEDArray, &LedArray9, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=3*8; index_j<3*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
}
}