制作电脑显示器流光溢彩

之前我发了一个显示器流光溢彩的视频,颜色效果还是很不错的。本文就给大家说说制作方法,过程非常简单,相信每个人都可以轻松搞定。
显示器流光溢彩

1、准备材料

需要用到的材料如下:

ws2812b灯带(带背胶);
arduino (nano、uno都ok);
usb线;
导线(杜邦线);
AmbiBox软件;
arduino软件;

2、贴灯带和接线

将灯带贴到显示器背面,具体贴法根据自己显示器的情况灵活安排,我的是这样贴的。

然后将灯带的三根线接到arduino上,分别是5v,GND和信号线,信号线接D2就行。

3、下载arduino代码

打开arduino开发环境,首先安装FastLED库,代码用了这个库来驱动ws2812b。

新建工程,将下面的代码复制到arduino IDE中,修改一下NUM_LEDS宏的值为你的灯的个数,修改DATA_PIN为灯带数据线接的arduino端口号。

 
  1. /*
  2. * <a class="decoration-color" href="https://buy.icxbk.com/index.php?ctl=Product&met=lists&key_type=1&keywords=arduino" target="_blank">Arduino</a> interface for the use of WS2812 strip LEDs
  3. * Uses Adalight protocol and is compatible with Boblight, Prismatik etc...
  4. * "Magic Word" for synchronisation is 'Ada' followed by LED High, Low and Checksum
  5. * @author: Wifsimster <[email protected]>
  6. * @library: FastLED v3.001
  7. * @date: 11/22/2015
  8. */
  9. #include "FastLED.h"
  10. #define NUM_LEDS 39 //(灯带一共有多少个LED?)
  11. #define DATA_PIN 2 //(绿色的数据线接在arduino几号端口?)
  12.  
  13. // Baudrate, higher rate allows faster refresh rate and more LEDs (defined in /etc/boblight.conf)
  14. #define serialRate 115200
  15.  
  16. // Adalight sends a "Magic Word" (defined in /etc/boblight.conf) before sending the pixel data
  17. uint8_t prefix[] = {'A', 'd', 'a'}, hi, lo, chk, i;
  18.  
  19. // Initialise LED-array
  20. CRGB leds[NUM_LEDS];
  21.  
  22. void setup() {
  23. // Use NEOPIXEL to keep true colors
  24. FastLED.addLeds<neopixel, data_pin="">(leds, NUM_LEDS);
  25.  
  26. // Initial RGB flash
  27. LEDS.showColor(CRGB(255, 0, 0));
  28. delay(500);
  29. LEDS.showColor(CRGB(0, 255, 0));
  30. delay(500);
  31. LEDS.showColor(CRGB(0, 0, 255));
  32. delay(500);
  33. LEDS.showColor(CRGB(0, 0, 0));
  34.  
  35. Serial.begin(serialRate);
  36. // Send "Magic Word" string to host
  37. Serial.print("Ada\n");
  38. }
  39.  
  40. void loop() {
  41. // Wait for first byte of Magic Word
  42. for(i = 0; i < sizeof prefix; ++i) {
  43. waitLoop: while (!Serial.available()) ;;
  44. // Check next byte in Magic Word
  45.  
  46. if(prefix[i] == Serial.read()) continue;
  47. // otherwise, start over
  48. i = 0;
  49. goto waitLoop;
  50. }
  51.  
  52. // Hi, Lo, Checksum
  53. while (!Serial.available()) ;;
  54. hi=Serial.read();
  55. while (!Serial.available()) ;;
  56. lo=Serial.read();
  57. while (!Serial.available()) ;;
  58. chk=Serial.read();
  59.  
  60. // If checksum does not match go back to wait
  61. if (chk != (hi ^ lo ^ 0x55)) {
  62. i=0;
  63. goto waitLoop;
  64. }
  65.  
  66. memset(leds, 0, NUM_LEDS * sizeof(struct CRGB));
  67. // Read the transmission data and set LED values
  68. for (uint8_t i = 0; i < NUM_LEDS; i++) {
  69. byte r, g, b;
  70. while(!Serial.available());
  71. r = Serial.read();
  72. while(!Serial.available());
  73. g = Serial.read();
  74. while(!Serial.available());
  75. b = Serial.read();
  76. leds[i].r = r;
  77. leds[i].g = g;
  78. leds[i].b = b;
  79. }
  80.  
  81. // Shows new values
  82. FastLED.show();

修改完毕后就可以编译下载了。这个用过arduino应该都会,我就不罗嗦了。下载完要保持usb线的连接,后边上位机软件会通过它给arduino发送命令和数据。

4、AmbiBox下载安装配置

AmbiBox是我们将会用到的上位机软件,大家可以到它们官网下载,我也会把安装包共享。

安装都是常规步骤,我就不多说了。安装完后打开软件,选择Intelligent backlight display,我们从上到下一一设置。

首先要勾选Use backlight,否则灯带不会跟着屏幕变化。

Mode下拉菜单提供了5种显示方式: 屏幕捕获、静态背景、动态背景、跟随音乐、插件。流光溢彩的效果是屏幕捕获的方式,我们这里选择第一个。

全文阅读:https://www.icxbk.com/article/detail/1652.html

猜你喜欢

转载自blog.csdn.net/ICXBK/article/details/108098733