[项目]8*8 LED点阵多彩时钟 精华

14408浏览
查看: 14408|回复: 6

[项目] 8*8 LED点阵多彩时钟

[复制链接]
楼主前一阵子弄来一块8*8的LED模块,想用来做贪吃蛇或俄罗斯方块吧来玩玩看吧,又觉得似乎有一点老套。思来想去,觉得不如做个小“手表”吧,方方的和现在很多智能手表一样呢 :) ,大小也比较合适。
由于一块点阵上一共只有64个点,楼主只能把表盘浓缩一下,用独特一些的方式来表示时间,来猜猜看下面的视频中显示的是几点吧~



铛铛铛~正确答案是11:59分到12:00的转换!你猜对了嘛~下面就让我来解释一下怎么读懂这块表吧

8*8 LED点阵多彩时钟图1


图中的紫色部分,应该是最好看懂的吧,一亮一灭代表1秒的流逝
而蓝色部分,就如我们日常的表一样,显示的是小时,最顶端为12,最下端为6;
橙色部分所显示的是具体的分钟,范围是0-15;但一小时有60分钟,就用绿色部分显示的是当前时间是一小时内的第几个15分钟,
因此右上角亮为0-14,右下角则代表15-29,左下角20-44,左上角45-59; 60则又会循环回0

视频中左上角的三角亮起,外围红灯亮起14颗,所以代表45+14=59分,跳转后右上角亮起,红灯亮15颗,代表0
在这里楼主选择了用亮15颗代表0/15,是想让在如9:15时灯全部亮起,当然你也可以修改代码用全灭来代表0/15

怎么样,是不是很“搞”啊,楼主其实也是不愿意这样的啊!

在构思这块表盘的时候,楼主可是煞费苦心,要知道,因为8是偶数,只要有一行是亮奇数个像素点的话,就会导致整个图案的不对称,尝试了各种可能性发现如上的排列方式还算不错,不仅15是60的分子,剩下来的像素点也正好分成了四块,真是一件不容易的事情!

废话不多说啦,来看看这个有些小“蛇精”的表是怎么做的吧!

一、所需元件

8*8 双色I2C点阵 *1
Arduino Uno *1
DS1370时钟模块 *1
导线若干

二、连线


将各部件按下图所示连接:

8*8 LED点阵多彩时钟图4

小贴士:Uno上的SCL,SDA在 数字端Aref的左边,可以通过观察UNO的背面找到标识;




三、库文件安装

下载附件adafruit_ledbackpack.zip
下载附件adafruit_gfx.zip


四、识别点阵模块地址

I2C地址位
模块后有A0 A1 A2三个空焊盘 断开为零 短接为1
A0
A1
A2
地址码
0000x70
1000x71
0100x72
1100x73
0010x74
1010x75
0110x76
1110x77




五、烧入代码
在理解完以下的代码以后,如果有别的显示时间的想法,比如你有更多的点阵模块的话,你大可以改动代码,做出不同的动画效果,期待更多作品哟~
  1. /*
  2. Finished by YU SUN on 08/11/2015
  3. This is the code for an 8*8 LED Matrix Clock.
  4. The time can be set everytime the program is compiled.
  5. */
  6. #include <Wire.h>
  7. #include <Adafruit_LEDBackpack.h>
  8. #include <Adafruit_GFX.h>
  9. #include <RTClib.h>
  10. RTC_DS1307 RTC; //utilize the RTC library to keep track of time
  11. Adafruit_BicolorMatrix matrix = Adafruit_BicolorMatrix(); //utilize the Adafruit library to drive the LED matrix
  12. long currentTime=0;
  13. long prevTime=0;
  14. int h =0;//hour
  15. int m =0;//minute
  16. int part=0;//which 15 mins segment it's in
  17. boolean first = true;// the first time to display time
  18. void setup() {
  19.   Serial.begin(9600);
  20.   RTC.begin();
  21.   matrix.begin(0x72);  // pass in the address
  22.   matrix.clear();
  23.    if (! RTC.isrunning()) {
  24.     Serial.println("RTC is NOT running!");
  25.   }
  26.     RTC.adjust(DateTime(2015, 8, 11,16, 16, 10));// manually set the time
  27.     DateTime now = RTC.now(); // get the time from RTC
  28.   h = (now.hour());
  29.   if(h >= 12){
  30.     h = (h - 12); //-12 because RTC is 24 Hour but there are only 12 LEDS on inner ring
  31.    
  32.   }
  33.   part=((now.minute()/15))%4;// get which 15min section time is in
  34.   m=(now.minute());
  35.   
  36. }
  37. void loop(){
  38.   //reset hour once it reaches 12
  39.   if (h==12){
  40.   h=0;
  41.   }
  42.   Serial.print("hour");//for debugging purposes
  43.   Serial.println(h,DEC);
  44.    for(h;h<12;h++){
  45.   hoursAnimation(h);// show the animation for hour
  46.   //reset minute once it reaches 60
  47.   if (m==60){
  48.   m=0;
  49.   }
  50.    for(m;m<60;m++){// the minute loop
  51.    //increment part as time passes by
  52.      if (first!=true && m%15==0){
  53.      part++;
  54.       if (part==4){//reset part
  55.       part=0;
  56.       }
  57.      }
  58.   minutesAnimation(m%15);//animation for mins
  59.   Serial.print("part");
  60.   Serial.println(part);
  61.   partAnimation(part);//animation for part
  62.   // Seconds loop
  63.      for(int s=0; s<60; s++){
  64.         while(currentTime - prevTime < 0.5){ // waits for RTC to advance 1 second before continuing
  65.         DateTime now = RTC.now();
  66.           prevTime = currentTime;
  67.           currentTime = now.unixtime();
  68.         }
  69.      if(s != 0 ){
  70.          matrix.drawPixel(4,4,LED_GREEN);
  71.          matrix.writeDisplay();
  72.          delay(500);
  73.          matrix.drawPixel(4,4,0);
  74.          matrix.writeDisplay();
  75.          delay(500);
  76.          }
  77. }
  78.    }
  79.    }
  80. }
  81. void minutesAnimation(int c){
  82. Serial.print("min");
  83.   Serial.println(c);
  84.   // draw the whole min line if it's the first time operating
  85.   if (first== true){
  86.     if(0<c&&c<=8){
  87.       if (c==1){
  88.       clearmin();// clear the min display before writing new ones
  89.       }
  90.      matrix.drawLine(0,0,c-1,0,LED_GREEN);
  91.      matrix.writeDisplay();
  92.    }else if (8<c&&c<15){
  93.      matrix.drawLine(0,0,7,0,LED_GREEN);
  94.      matrix.drawLine(0,0,0,c-8,LED_GREEN);
  95.      matrix.writeDisplay();
  96.    }else if (c==0){
  97.      matrix.drawLine(0,0,0,7,LED_GREEN);
  98.      matrix.drawLine(0,0,7,0,LED_GREEN);
  99.      matrix.writeDisplay();
  100.    }
  101.    first = false;
  102.   }else {// draw one pixel at one time
  103.    if(0<c&&c<=8){
  104.    
  105.      if (c==1){
  106.      clearmin();
  107.      }
  108.      matrix.drawPixel(c-1,0,LED_GREEN);
  109.      matrix.writeDisplay();
  110.    }else if (8<c&&c<15){
  111.      matrix.drawPixel(0,c-8,LED_GREEN);
  112.      matrix.writeDisplay();
  113.    }else if (c==0){
  114.      matrix.drawLine(0,0,0,7,LED_GREEN);
  115.      matrix.drawLine(0,0,7,0,LED_GREEN);
  116.      matrix.writeDisplay();
  117.    }
  118. }
  119. }
  120. void clearmin(){
  121.   matrix.drawLine(0,0,0,7,0);
  122.   matrix.drawLine(0,0,7,0,0);
  123.   matrix.writeDisplay();
  124. }
  125. void hoursAnimation(int a){
  126.   //lines for all hour displays
  127.   matrix.drawLine(4,1,7,4,0);
  128.   matrix.drawLine(7,4,4,7,0);
  129.   matrix.drawLine(4,7,1,4,0);
  130.   matrix.drawLine(1,4,4,1,0);
  131.   
  132.   matrix.drawLine(4,1,7,4,LED_RED);
  133.   matrix.drawLine(7,4,4,7,LED_RED);
  134.   matrix.drawLine(4,7,1,4,LED_RED);
  135.   matrix.drawLine(1,4,4,1,LED_RED);
  136.   matrix.writeDisplay();
  137.   
  138.   Serial.print(a);
  139.   //show the exact hour
  140.     if (0<=a&&a<=2){
  141.      matrix.drawPixel(7-a,4+a,0);
  142.     matrix.drawPixel(7-a,a+4,LED_GREEN);
  143.     matrix.writeDisplay();
  144.    
  145.     }else if (3<=a&&a<=5){
  146.     matrix.drawPixel(4-a%3,7-a%3,0);
  147.     matrix.drawPixel(4-a%3,7-a%3,LED_GREEN);
  148.     matrix.writeDisplay();
  149.     }else if (6<=a&&a<=8){
  150.     matrix.drawPixel(1+a%3,4-a%3,0);
  151.     matrix.drawPixel(1+a%3,4-a%3,LED_GREEN);
  152.     matrix.writeDisplay();
  153.     }else{
  154.     matrix.drawPixel(4+a%3,1+a%3,0);
  155.     matrix.drawPixel(4+a%3,1+a%3,LED_GREEN);
  156.     matrix.writeDisplay();
  157.     }
  158. }
  159. void partAnimation(int b){
  160.   if (b==3){
  161.    matrix.fillTriangle(3,1,1,1,1,3,0);
  162.    matrix.fillTriangle(5,1,7,1,7,3,LED_YELLOW);
  163.    matrix.writeDisplay();
  164.   }else if (b ==0){
  165.    matrix.fillTriangle(5,1,7,1,7,3,0);
  166.    matrix.fillTriangle(7,5,7,7,5,7,LED_YELLOW);
  167.    matrix.writeDisplay();
  168.   }else if (b ==1){
  169.    matrix.fillTriangle(7,5,7,7,5,7,0);
  170.    matrix.fillTriangle(1,5,1,7,3,7,LED_YELLOW);
  171.    matrix.writeDisplay();
  172.   }else if (b ==2){
  173.    matrix.fillTriangle(1,5,1,7,3,7,0);
  174.    matrix.fillTriangle(3,1,1,1,1,3,LED_YELLOW);
  175.    matrix.writeDisplay();
  176.   }
  177. }
复制代码







touchfree  高级技师

发表于 2015-8-12 11:02:17

够创意,比苹果表好看多了
回复

使用道具 举报

dbc0301  高级技匠

发表于 2015-8-12 12:30:11

楼主还可以在程序里加入一些表情。:)
回复

使用道具 举报

Jane  高级技匠

发表于 2015-8-12 15:52:16

很有创意~楼主脑洞挺大哈~
回复

使用道具 举报

sun20100480  初级技师
 楼主|

发表于 2015-8-12 17:41:55

dbc0301 发表于 2015-8-12 12:30
楼主还可以在程序里加入一些表情。

是啊,如果有按钮的话就可以设置成休眠模式时显示表情,按钮按了以后显示时间,还有挺多可能性哒~
回复

使用道具 举报

caojinrong  学徒

发表于 2017-5-13 12:37:29

您好,我在学习您的这个,在我的电脑上,提示缺少C:\Users\lucky\AppData\Local\Temp\arduino_modified_sketch_284844\bicolor8x8.pde:19:20: fatal error: RTClib.h: No such file or directory
这个库文件,您这个库文件在哪呢?谢谢您:'(
回复

使用道具 举报

袋鼠_zgz13  学徒

发表于 2021-9-14 15:11:24

您好,请问是否可以用arduino nano代替UNO,代码要怎么修改?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail