2021-12-17 21:43:49 [显示全部楼层]
2018浏览
查看: 2018|回复: 4

Mind+Python流光溢彩灯

[复制链接]
本帖最后由 云天 于 2021-12-17 21:50 编辑

Mind+Python流光溢彩灯图2


【项目设计】
”流光溢彩灯“有非常炫酷的效果,它可以根据不同的画面和内容,配备在显示器后方的墙壁上投射出不同颜色的LED灯光。这个流光溢彩灯能够通过Python识别当前屏幕上显示的内容,自动调节出与当前屏幕画面相近的灯效,将屏幕上的画面延伸到屏幕之外,营造出更大的让人身临其境的视觉氛围。
【硬件设计】
硬件使用DF Arduino uno,控制LED灯带。
Mind+Python流光溢彩灯图7


Mind+Python流光溢彩灯图8


Mind+Python流光溢彩灯图4


Mind+Python流光溢彩灯图1


Mind+Python流光溢彩灯图3


Mind+Python流光溢彩灯图6


Mind+Python流光溢彩灯图5


【程序设计】

软件使用Mind+Python模式,通过“ctypes”库获取屏幕上某个坐标的颜色,再通过“Pinpong”库让Arduino控制LED灯带变幻相应颜色。(原创Python程序)

  1. from ctypes import *  # 获取屏幕上某个坐标的颜色
  2. import time
  3. from pinpong.board import Board,Pin,NeoPixel
  4. import numpy as npy
  5. NEOPIXEL_PIN = Pin.D2
  6. PIXELS_NUM = 60 #灯数
  7. Board("uno").begin()  #初始化,选择板型和端口号,不输入端口号则进行自动识别
  8. np = NeoPixel(Pin(NEOPIXEL_PIN), PIXELS_NUM)
  9. gdi32 = windll.gdi32
  10. user32 = windll.user32
  11. user32.SetProcessDPIAware()
  12. w, h= [user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)]
  13. def get_color(x, y):
  14.     hdc = user32.GetDC(None)  # 获取颜色值
  15.     pixel = gdi32.GetPixel(hdc, x, y)  # 提取RGB值
  16.     r = pixel & 0x0000ff
  17.     g = (pixel & 0x00ff00) >> 8
  18.     b = pixel >> 16
  19.     return (int(r),int(g),int(b))
  20. success=True
  21. n0=13
  22. h0=int(h/n0)
  23. n1=22
  24. w1=int(w/n1)
  25. n2=14
  26. h2=int(h/n2)
  27. while success:
  28.     #右侧
  29.     data=[]
  30.     for j in range(0,n0):
  31.       t0=h0*j+int(h0/2)
  32.       rgb1,rgb2,rgb3=get_color(w-20, t0)
  33.       k=12-j
  34.       np[k] =(rgb1,rgb2,rgb3)
  35.      #顶灯
  36.     data=[]
  37.     for j in range(0,n1):
  38.      t1=w1*j+int(w1/2)
  39.      rgb1,rgb2,rgb3=get_color(t1, 20)
  40.      k=34-j
  41.      np[k] =(rgb1,rgb2,rgb3)
  42.     #左侧
  43.     for j in range(0,n2):
  44.       t2=h2*j+int(h2/2)
  45.       rgb1,rgb2,rgb3=get_color(20, t2)
  46.       k=35+j
  47.       np[k] =(rgb1,rgb2,rgb3)
  48.   
  49.    
  50.    
复制代码
由于电脑配置原因,只使用了屏幕上相应的一个点来控制一个灯的颜色,如果你的电脑配置高,可以使用以下程序(使用多个点取平均颜色)试一试。我自己的电脑运行缓慢,显示效果不好。
  1. from ctypes import *  # 获取屏幕上某个坐标的颜色
  2. import time
  3. from pinpong.board import Board,Pin,NeoPixel
  4. import numpy as npy
  5. NEOPIXEL_PIN = Pin.D2
  6. PIXELS_NUM = 60 #灯数
  7. Board("uno").begin()  #初始化,选择板型和端口号,不输入端口号则进行自动识别
  8. np = NeoPixel(Pin(NEOPIXEL_PIN), PIXELS_NUM)
  9. gdi32 = windll.gdi32
  10. user32 = windll.user32
  11. user32.SetProcessDPIAware()
  12. w, h= [user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)]
  13. def get_color(x, y):
  14.     hdc = user32.GetDC(None)  # 获取颜色值
  15.     pixel = gdi32.GetPixel(hdc, x, y)  # 提取RGB值
  16.     r = pixel & 0x0000ff
  17.     g = (pixel & 0x00ff00) >> 8
  18.     b = pixel >> 16
  19.     return (int(r),int(g),int(b))
  20. success=True
  21. n0=13
  22. h0=int(h/n0)
  23. n1=22
  24. w1=int(w/n1)
  25. n2=14
  26. h2=int(h/n2)
  27. print(h)
  28. temp=[]
  29. while success:
  30.     #右侧
  31.     data=[]
  32.     for j in range(0,n0):
  33.       t0=h0*j+int(h0/2)-1
  34.       tp=h0*j+int(h0/2)+1
  35.       for m in range(t0,tp):
  36.        rgb1,rgb2,rgb3=get_color(w-20, m)
  37.       data.append((rgb1,rgb2,rgb3))
  38.       temp=npy.mean(data,0)
  39.       k=12-j
  40.       
  41.       np[k] =(int(temp[0]),int(temp[1]),int(temp[2]))
  42.      #顶灯
  43.     data=[]
  44.     for j in range(0,n1):
  45.      t1=w1*j+int(w1/2)-1
  46.      tp=h0*j+int(h0/2)+1
  47.      for m in range(t1,tp):
  48.        rgb1,rgb2,rgb3=get_color(m, 20)
  49.      data.append((rgb1,rgb2,rgb3))
  50.      temp=npy.mean(data,0)
  51.      k=34-j
  52.      np[k] =(int(temp[0]),int(temp[1]),int(temp[2]))
  53.     #左侧
  54.     data=[]
  55.     for j in range(0,n2):
  56.       t2=h2*j+int(h2/2)-1
  57.       tp=h0*j+int(h0/2)+1
  58.       for m in range(t2,tp):
  59.         rgb1,rgb2,rgb3=get_color(20, m)
  60.       data.append((rgb1,rgb2,rgb3))
  61.       temp=npy.mean(data,0)
  62.       k=35+j
  63.       np[k] =(int(temp[0]),int(temp[1]),int(temp[2]))
  64.     print(1)     
  65.    
  66.    
复制代码


【演示视频】







hnyzcj  版主

发表于 2021-12-18 08:22:38

回复

使用道具 举报

glwz007  初级技匠

发表于 2021-12-22 14:40:27

非常好的创意!
回复

使用道具 举报

flythief  学徒

发表于 2022-4-12 09:22:44

您好,看了您的Python灯带帖子,想请教一些问题
我是硬件开发新手,想请问下做出您这个灯带需要学习哪些方面的知识以及准备哪些东西?
回复

使用道具 举报

云天  初级技神
 楼主|

发表于 2022-4-13 09:21:45

flythief 发表于 2022-4-12 09:22
您好,看了您的Python灯带帖子,想请教一些问题
我是硬件开发新手,想请问下做出您这个灯带需要学习哪些方 ...

python语言,pinpong库,Arduino三个
回复

使用道具 举报

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

本版积分规则

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

硬件清单

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

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

mail