[进阶]LED时钟

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

[进阶] LED时钟

[复制链接]
LED炫彩时钟~

【效果图】
LED时钟图1


【介绍】
楼主也不免俗地做起了LED时钟呢~看到了论坛里的这篇帖子,给脑洞点赞!我用的LED圆盘是三个圆环拼起来的,LED数量分别为121624。用12个的那一圈表示了小时,在表示分钟的方法上犯难了,最后决定用十进制,用前六个LED灯表示十位数字,分别为0-5,以绿色为背景用后十位代表个位数字,分别为0-9,以蓝色为背景;用最外一圈的闪烁代表秒针,颜色随机。上面的动图就是时间从1点36变成1点37的效果。


视频

视频效果一般,肉眼看的话,被点亮的led也是可以看清数字的,ipad mini1的摄像头果然不行


【硬件清单】
灯环/灯带/灯盘/灯珠


【连线图】
LED时钟图3
因为没有找到灯盘的SVG图就只在左侧标注了连线脚


【库文件】
在这个应用中我用到了LED的库以及时钟模块的库


【测试】
我们先需要用以下代码测试一下时钟模块看时间是否正确
  1. #include <Wire.h>
  2. #include <DS1307.h>
  3. String comdata = "";
  4. //store the current time data
  5. int rtc[7];
  6. //light pin
  7. int ledPin =  13;
  8. //initial light
  9. void setup()
  10. {
  11.   DDRC |= _BV(2) | _BV(3); // POWER:Vcc Gnd
  12.   PORTC |= _BV(3); // VCC PINC3
  13.   pinMode(ledPin, OUTPUT);
  14.   //initial baudrate
  15.   Serial.begin(9600);
  16.   //get current time
  17.   RTC.get(rtc, true);
  18.   RTC.SetOutput(DS1307_SQW32KHZ);
  19. }
  20. void loop()
  21. {
  22.   int i;
  23.   //get current time
  24.   RTC.get(rtc, true);
  25.   //print current time format : sec min hour week day month year
  26.   for (i = 0; i < 7; i++)
  27.   {
  28.     Serial.print(rtc[i]);
  29.     Serial.print(" ");
  30.   }
  31.   //blink the light
  32.   Serial.println();
  33.   digitalWrite(ledPin, HIGH);
  34.   delay(500);
  35.   digitalWrite(ledPin, LOW);
  36.   delay(500);
  37. }
复制代码
如果得到的时间并不正确,我们需要重新烧入时间,wiki中给的方法有些繁琐,而且代码上传的时间无法估计,重新设定的时间总于真正的时间有点小误差,我在社区里发现里这个帖子,可能会帮助大家更简便地设置时间。用电脑时间实时更新DS1307时钟模块 DFR0151


【代码】
  1. #include <Adafruit_NeoPixel.h>
  2. #include <Wire.h>
  3. #include <DS1307.h>
  4. #ifdef __AVR__
  5.   #include <avr/power.h>
  6. #endif
  7. //store the current time data
  8. int rtc[7];
  9. #define PIN3 10
  10. #define PIN4 9
  11. #define PIN5 8
  12. int r, g, b;
  13. // Parameter 1 = number of pixels in round3
  14. // Parameter 2 = Arduino pin number (most are valid)
  15. // Parameter 3 = pixel type flags, add together as needed:
  16. //   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
  17. //   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
  18. //   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
  19. //   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
  20. Adafruit_NeoPixel round3 = Adafruit_NeoPixel(12, PIN3, NEO_GRB + NEO_KHZ800);
  21. Adafruit_NeoPixel round4 = Adafruit_NeoPixel(16, PIN4, NEO_GRB + NEO_KHZ800);
  22. Adafruit_NeoPixel round5 = Adafruit_NeoPixel(24, PIN5, NEO_GRB + NEO_KHZ800);
  23. void setup() {
  24.   //get current time
  25.   RTC.get(rtc, true);
  26.   RTC.SetOutput(DS1307_SQW32KHZ);
  27.   round3.begin();
  28.   round4.begin();
  29.   round5.begin();
  30.   // This initializes the NeoPixel library.
  31.   Serial.begin(9600);
  32. }
  33. void loop() {
  34.     //get current time
  35.     int ten, unit, minutes, hours;
  36.     RTC.get(rtc, true);
  37.     //print current time format : sec min hour week day month year
  38.     for (int i = 0; i < 7; i++)
  39.     {
  40.       Serial.print(rtc[i]);
  41.       Serial.print(" ");
  42.       minutes = rtc[1];
  43.       hours = rtc[2];
  44.       }
  45.       unit = minutes%10;
  46.       ten = int(minutes/10);
  47.       if (hours >= 12) {
  48.         hours = hours-12;
  49.       }else{
  50.         hours = rtc[2];
  51.       }
  52.     //minute
  53.     round4.setPixelColor(ten, round4.Color(30,210,130));
  54.     round4.setPixelColor(unit+6, round4.Color(30,150,200));
  55.     round4.show();
  56.     for (int i = 0; i < 6; i++)
  57.     {
  58.       round4.setPixelColor(i, round4.Color(1,12,8));
  59.     }
  60.     for (int i = 6; i < 16; i++)
  61.     {
  62.       round4.setPixelColor(i, round4.Color(1,9,12));
  63.     }
  64.    
  65.     //hour
  66.     round3.setPixelColor(hours, round3.Color(150,142,39));
  67.     round3.show();
  68.     for (int i = 0; i < 12; i++)
  69.     {
  70.       round3.setPixelColor(i, round3.Color(14,11,3));
  71.     }
  72.     //blink
  73.     r = random(1,7);
  74.     g = random(1,7);
  75.     b = random(1,7);
  76.     for (int i = 0; i < 24; i++){
  77.       round5.setPixelColor(i, round5.Color(r,g,b)); // random color
  78.     }
  79.     round5.show();
  80.     delay(500);
  81.     for (int i = 0; i < 24; i++){
  82.       round5.setPixelColor(i, round5.Color(0,0,0));
  83.     }
  84.     round5.show();
  85.     delay(500);
  86.   }
复制代码


【3D外壳】
用了SolidWorks做了一个外壳~在电脑上看觉得敲美丽,然而。。。
在和打印机较劲一整天之后它终于给我打出来一个还像样儿的外壳,楼主表示已经很安慰了。。。
LED时钟图4



丄帝De咗臂  高级技匠

发表于 2016-1-6 18:21:50

棒死了,顶起来
回复

使用道具 举报

dsweiliang  初级技神

发表于 2016-1-6 23:13:00

非常棒
回复

使用道具 举报

孙毅  初级技匠

发表于 2016-1-6 23:59:18

叼死了~~~~
回复

使用道具 举报

hnyzcj  版主

发表于 2016-1-7 11:19:51

其实我很需要这个
回复

使用道具 举报

源代码  中级技匠

发表于 2016-1-15 19:58:15

楼主好棒棒啊
回复

使用道具 举报

20060606  高级技匠

发表于 2020-8-20 06:19:37

好创意,赞一个
回复

使用道具 举报

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

本版积分规则

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

硬件清单

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

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

mail