960浏览
查看: 960|回复: 3

【智控万物】我为冬奥会加油——倒计时沙漏灯

[复制链接]
【项目背景】
1.jpg


2019年5月10日晚,北京冬奥会倒计时1000天活动在奥林匹克公园玲珑塔南侧广场举行。活动中,北京2022年冬奥会倒计时装置正式启动。


1ac8-kirmaiu0808634.jpg


2021年2月4日,位于北京奥林匹克公园核心区中心位置的玲珑塔,北京冬奥会倒计时钟显示365天。玲珑塔南起500余米的国家体育场鸟巢,在2008年见证过国人的奥运梦想与荣光后,一年之后的夜晚,将迎来一场世界奥林匹克冰雪盛宴的开幕。


北京冬季奥运会设7个大项,15个分项,109个小项。北京将主办冰上项目,张家口将主办雪上项目,延庆协办张家口举办雪上项目。


我在河北张家口,我为冬奥会加油。
【项目设计】
IMG_20210209_221537.jpg



使用LED灯带和掌控板,制作一个仿玲珑塔北京冬奥会倒计时钟。
【项目材料】
QQ截图20210209224310.png

炫彩 WS2812 LED灯带 3米(2条)https://www.dfrobot.com.cn/goods-852.html
QQ截图20210209224534.png

掌控板2.0(掌控宝)https://www.dfrobot.com.cn/goods-852.html
【项目制作】
IMG_20210208_121043.jpg


IMG_20210208_154855.jpg


IMG_20210209_190107.jpg


IMG_20210209_190121.jpg

【Mind+编程】
一、编号
IMG_20210209_225020_edit_40587049862036.jpg


因使用完整灯带,没有剪开,所以所有的灯都要重新对应编号。在编程时,也要使用列表将原灯号及新编号进行记录。才能对应控制每个灯的亮灭,完成显示效果。

二、程序初始化

TueFebruary-202102094888..png

1、每个灯带120个灯,共240个。数据线接掌控宝13口上。灯带单独供电,与掌控板要共地。
2、连接Wifi,获取时间。
3、倒计时的天数等时间,因图型中没有找到时间差处理方法,所以这几个值,后面用代码模式处理。
4、“灯列表”中,放的是灯的实际编号。因弯曲部分有灯,所显示出来的灯号并不都连续。(见制作图)
  1. [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,19,20,21,22,23,24,25,26,27,28,29,30,31,36,37,38,39,40,41,42,43,44,45,46,53,54,55,56,57,58,59,60,61,70,71,72,73,74,87,88,89,102,103,104,115,128,129,130,144,145,146,160,161,162,163,164,174,175,176,177,178,179,180,181,182,191,192,193,194,195,196,197,198,199,200,201,206,207,208,209,210,211,212,213,214215,216,217,218,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239]
复制代码
5、灯落下,为了形成沙堆的效果,需要对“灯堆”进行分层记录灯号。

  1. [239,206,201,174,130,225,218,191,182,128,115],[238,207,200,175,164,144,226,217,192,181,160,146,129],[237,208,199,176,163,227,216,193,180,161,145],[236,209,198,177,228,215,194,179,162],[235,210,197,229,214,195,178], [234,211,230,213,196], [233,231,212]
复制代码
并进行记录新编号(落灯堆序号)。

  1. [118,91,90,71,62,104,103,80,79,60,59],[117,92,89,72,70,63,105,102,81,78,66,65,61],[116,93,88,73,69,106,101,82,77,67,64],[115,94,87,74,107,100,83,76,68],[114,95,86,108,99,84,75], [113,96,109,98,85], [112,110,97]
复制代码
6、对中线灯进行记录编号(中线灯上下列表)

  1. [115,103,88,72,57,41,25,8]
复制代码
  1. [115,129,145,162,178,196,212,232]
复制代码
三、主程序

TueFebruary-202102094603..png

四、代码处理日期差,计算倒计时
  1. firstDay = (time.localtime()[0], time.localtime()[1], time.localtime()[2],time.localtime()[3],time.localtime()[4],time.localtime()[5],time.localtime()[6],time.localtime()[7],-1)
  2. endDay=(2022,2,4,20,0,0,1,35,-1)
  3. Time1=(time.mktime(endDay)-time.mktime(firstDay))
  4. Tian=(int(Time1/(24*3600)))
  5. Time2=Time1-Tian*24*3600
  6. Shi = int((Time2)/3600)
  7. Time3=Time2 - Shi*3600
  8. FenZhong = int((Time3)/60)
  9. #Miao = int(Time3-FenZhong*60)
  10. Miao =59
复制代码
五、MicroPython完成代码

  1. # MindPlus
  2. # mpython
  3. import font.digiface_44
  4. import font.digiface_21
  5. from mpython import *
  6. import neopixel
  7. import framebuf
  8. import network
  9. import ntptime
  10. import time
  11. import math
  12. def neopixel_range(rgb, start, end, color):
  13.   trend = -1 if end < start else 1
  14.   for i in range(start, end-1 if trend < 0 else end+1, trend):
  15.     rgb[i] = (color)
  16.   rgb.write()
  17. def display_font(_font, _str, _x, _y, _wrap, _z=0):
  18.   _start = _x
  19.   for _c in _str:
  20.     _d = _font.get_ch(_c)
  21.     if _wrap and _x > 128 - _d[2]: _x = _start; _y += _d[1]
  22.     if _c == '1' and _z > 0: oled.fill_rect(_x, _y, _d[2], _d[1], 0)
  23.     oled.blit(framebuf.FrameBuffer(bytearray(_d[0]), _d[2], _d[1],
  24.     framebuf.MONO_HLSB), (_x+int(_d[2]/_z)) if _c=='1' and _z>0 else _x, _y)
  25.     _x += _d[2]
  26. my_wifi = wifi()
  27. ws2812_P13 = neopixel.NeoPixel(Pin(Pin.P13), n=240, bpp=3, timing=1)
  28. ws2812_P13.fill((0, 0, 0))
  29. ws2812_P13.write()
  30. my_wifi.connectWiFi("sxs","smj080823")
  31. while not (my_wifi.sta.isconnected()):
  32.   pass
  33. ntptime.settime(8, "ntp.ntsc.ac.cn")
  34. firstDay = (time.localtime()[0], time.localtime()[1], time.localtime()[2],time.localtime()[3],time.localtime()[4],time.localtime()[5],time.localtime()[6],time.localtime()[7],-1)
  35. endDay=(2022,2,4,20,0,0,1,35,-1)
  36. Time1=(time.mktime(endDay)-time.mktime(firstDay))
  37. Tian=(int(Time1/(24*3600)))
  38. Time2=Time1-Tian*24*3600
  39. Shi = int((Time2)/3600)
  40. Time3=Time2 - Shi*3600
  41. FenZhong = int((Time3)/60)
  42. #Miao = int(Time3-FenZhong*60)
  43. Miao =59
  44. DengLieBiao = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,19,20,21,22,23,24,25,26,27,28,29,30,31,36,37,38,39,40,41,42,43,44,45,46,53,54,55,56,57,58,59,60,61,70,71,72,73,74,87,88,89,102,103,104,115,128,129,130,144,145,146,160,161,162,163,164,174,175,176,177,178,179,180,181,182,191,192,193,194,195,196,197,198,199,200,201,206,207,208,209,210,211,212,213,214215,216,217,218,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239]
  45. LuoDengDui = [[239,206,201,174,130,225,218,191,182,128,115],[238,207,200,175,164,144,226,217,192,181,160,146,129],[237,208,199,176,163,227,216,193,180,161,145],[236,209,198,177,228,215,194,179,162],[235,210,197,229,214,195,178], [234,211,230,213,196], [233,231,212]]
  46. LuoDengDuiXuHao = [[118,91,90,71,62,104,103,80,79,60,59],[117,92,89,72,70,63,105,102,81,78,66,65,61],[116,93,88,73,69,106,101,82,77,67,64],[115,94,87,74,107,100,83,76,68],[114,95,86,108,99,84,75], [113,96,109,98,85], [112,110,97]]
  47. ZhongXianDengShangLieBiao = [115,103,88,72,57,41,25,8]
  48. ZhongXianDengXiaLieBiao = [115,129,145,162,178,196,212,232]
  49. while True:
  50.   ws2812_P13.fill((0, 0, 0))
  51.   ws2812_P13.write()
  52.   LiangMieLieBiao = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
  53.   i = 0
  54.   FangXiang = 0
  55.   for index in range(60):
  56.     neopixel_range(ws2812_P13, (DengLieBiao[i]), (DengLieBiao[i]), (0, 0, 255))
  57.     i = (i + 1)
  58.   i = 0
  59.   if (FangXiang == 0):
  60.     LuoDengLieBiao = ZhongXianDengXiaLieBiao
  61.     LuoDengXuHao = [59,61,64,68,75,85,97,111]
  62.   else:
  63.     LuoDengLieBiao = ZhongXianDengShangLieBiao
  64.     LuoDengXuHao = [59,57,54,50,43,33,21,7]
  65.   for index in range(60):
  66.     YunXingShiJian = time.ticks_ms()
  67.     YunXingShiJian = time.ticks_ms()
  68.     j = 0
  69.     ZhongXianMieDengGeShu = 0
  70.     for index in range(len(LuoDengXuHao)):
  71.       if ((LiangMieLieBiao[(LuoDengXuHao[j])]) == 0):
  72.         ZhongXianMieDengGeShu = (ZhongXianMieDengGeShu + 1)
  73.       j = (j + 1)
  74.     if (ZhongXianMieDengGeShu > 0):
  75.       LuoDengJianGeShiJian = (0.5 / ZhongXianMieDengGeShu)
  76.     else:
  77.       LuoDengJianGeShiJian = 0.5
  78.     time.sleep(LuoDengJianGeShiJian)
  79.     neopixel_range(ws2812_P13, (DengLieBiao[i]), (DengLieBiao[i]), (0, 0, 0))
  80.     j = 0
  81.     while not (((j == len(LuoDengLieBiao)) or ((LiangMieLieBiao[(LuoDengXuHao[j])]) == 1))):
  82.       neopixel_range(ws2812_P13, (LuoDengLieBiao[j]), (LuoDengLieBiao[j]), (255, 0, 0))
  83.       time.sleep(LuoDengJianGeShiJian)
  84.       neopixel_range(ws2812_P13, (LuoDengLieBiao[j]), (LuoDengLieBiao[j]), (0, 0, 0))
  85.       j = (j + 1)
  86.     if (j == 8):
  87.       LiangMieLieBiao[(LuoDengXuHao[7])]=1
  88.       neopixel_range(ws2812_P13, 232, 232, (255, 0, 0))
  89.     else:
  90.       LuoDengDuiXing = (LuoDengDui[(j - 1)])
  91.       LuoDengDuiXingDengGeShu = len(LuoDengDuiXing)
  92.       LuoDengDuiXuHaoXing = (LuoDengDuiXuHao[(j - 1)])
  93.       LuoDengDuiXuHaoXingDengGeShu = len(LuoDengDuiXuHaoXing)
  94.       k = (LuoDengDuiXingDengGeShu - 1)
  95.       for index in range(LuoDengDuiXingDengGeShu):
  96.         if ((LiangMieLieBiao[(LuoDengDuiXuHaoXing[k])]) == 0):
  97.           if (k == 0):
  98.             neopixel_range(ws2812_P13, (LuoDengDuiXing[k]), (LuoDengDuiXing[k]), (255, 0, 0))
  99.             LiangMieLieBiao[(LuoDengDuiXuHaoXing[k])]=1
  100.             break
  101.           if ((k > ((math.floor((LuoDengDuiXingDengGeShu / 2))) - 1)) and ((LiangMieLieBiao[(LuoDengDuiXuHaoXing[((math.floor((LuoDengDuiXingDengGeShu / 2))) - 1)])]) == 0)):
  102.             pass
  103.           else:
  104.             neopixel_range(ws2812_P13, (LuoDengDuiXing[k]), (LuoDengDuiXing[k]), (255, 0, 0))
  105.             time.sleep(0.01)
  106.             neopixel_range(ws2812_P13, (LuoDengDuiXing[k]), (LuoDengDuiXing[k]), (0, 0, 0))
  107.         else:
  108.           neopixel_range(ws2812_P13, (LuoDengDuiXing[(k + 1)]), (LuoDengDuiXing[(k + 1)]), (255, 0, 0))
  109.           LiangMieLieBiao[(LuoDengDuiXuHaoXing[(k + 1)])]=1
  110.           break
  111.         k = (k - 1)
  112.     i = (i + 1)
  113.     oled.fill(0)
  114.     display_font(font.digiface_44, (str(Tian)), 0, 0, True, 2)
  115.     display_font(font.digiface_21, (str(Shi)), 0, 45, True, 2)
  116.     display_font(font.digiface_21, (str(FenZhong)), 55, 45, True, 2)
  117.     display_font(font.digiface_21, (str(Miao)), 103, 45, True, 2)
  118.     oled.show()
  119.     if (Miao == 0):
  120.       if (FenZhong == 0):
  121.         if (Shi == 0):
  122.           if (Tian == 0):
  123.             oled.DispChar("今天开幕", 42, 22, 1)
  124.             oled.show()
  125.             break
  126.           else:
  127.             Tian = (Tian - 1)
  128.           Shi = 23
  129.         else:
  130.           Shi = (Shi - 1)
  131.         FenZhong = 59
  132.       else:
  133.         FenZhong = (FenZhong - 1)
  134.       Miao = 59
  135.     else:
  136.       Miao = (Miao - 1)
  137.     while not (((time.ticks_ms() - YunXingShiJian) > 1000)):
  138.       pass
复制代码
【演示视频】




rzyzzxw  版主

发表于 2021-2-17 09:06:54

太帅啦
回复

使用道具 举报

20870886  见习技师

发表于 2021-10-28 09:11:34

必须点赞,有创意:)
回复

使用道具 举报

丨偏执狂丨  学徒

发表于 2021-11-6 17:05:47

很有创意
回复

使用道具 举报

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

本版积分规则

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

硬件清单

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

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

mail