创客实战 | 用Arduino 制作一款美轮美奂的LED 矩阵彩灯
前言
这期的主角是一款美轮美奂的灯具,甚至可以编程实现让它显示几个字母,妥妥得就是一个表白神器。

这是一款 LED 矩阵彩灯,使用标准 WS2812b LED,用木制边框组成一个圆柱形的灯体。
视频先睹为快。

材料
WS2812b LED x100(30个/米)
Arduino x1
5V电源(100个 WS2812b LED 的最大功率为 100x60mA = 6A)
导线若干
外壳(找商家定制)
步骤
定制外壳(参考)





模型的链接为:https://a360.co/2OC2kvZ
激光切割的 SVG 文件请点击阅读原文下载,可凭借该文件直接找淘宝商家定制。
LED 灯条接线



每一个 LED 灯条上都有5个 LED 灯,并用胶水粘到载体上。
1、灯带的 DI 和 DO 引脚以Z字形的方式连接在一起,将第一条带的 DO 与下一条纹的 DI 连接,以此类推。
2、每个半圆形的需要 10 条灯带。5V 和 GND 仅在条带的一侧连接。电线的长度与矩阵的条带所需布线的长度要相匹配。
3、将 LED 灯条安装到位之前,需要将所有结点用胶固定好。
4、将十个灯条用胶水固定到每半个圆柱体上。一个半圆的 DO 连接到另一半圆的 DI。第一个半圆的DI 是 Arduino 的输入。
Arduino接线

测试


编程
#include #include #include #include #ifndef PSTR#define PSTR#endif#define PIN 4
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(20, 5, PIN,NEO_MATRIX_TOP + NEO_MATRIX_LEFT +NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG,NEO_GRB + NEO_KHZ800);
const uint16_t colors[] = {matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255) };
void setup() {matrix.setFont(&TomThumb);matrix.begin();matrix.setTextWrap(false);matrix.setBrightness(40);matrix.setTextColor(colors[0]);}
int x = matrix.width();int pass = 0;
void loop() {matrix.fillScreen(0);matrix.setCursor(x, 5);matrix.print(F("HELLO"));if(--x < -36) {x = matrix.width();if(++pass >= 3) pass = 0;matrix.setTextColor(colors[pass]);}matrix.show();delay(100);}
源码文件请点击底部阅读原文下载。
代码中设置了两种模式,在 cylinder.py 的开头定义了 PI 变量。
1、PI=False,是模拟模式,将启动一个 Python 程序用来测试所有的动画效果。需要先安装程序依赖的所有库(如 pygame,numpy 等)。在模拟模式下,圆柱体显示为 5×20 像素矩阵。




2、PI=True,这将驱动树莓派的 GPIO 18# 引脚。可以使用参数自由添加其他效果。
文本使用了3×5像素的字体,由于高度有限,不是所有字母都可以完整的显示。
--end--
声明:本文章由网友投稿作为教育分享用途,如有侵权原作者可通过邮件及时和我们联系删除:freemanzk@qq.com