可编辑点阵汉字滚动广告显示器代码
时间: 2023-06-18 21:04:52 浏览: 59
以下是一个可编辑点阵汉字滚动广告显示器的代码示例,使用Arduino开发板和LED点阵模块:
```c++
#include <Adafruit_GFX.h>
#include <Adafruit_LEDBackpack.h>
#include <Wire.h>
Adafruit_8x16matrix matrix = Adafruit_8x16matrix();
// 定义点阵显示的宽度和高度
const int MATRIX_WIDTH = 16;
const int MATRIX_HEIGHT = 8;
// 定义要显示的文本
String text = "欢迎来到我们的商店!";
void setup() {
// 初始化点阵
matrix.begin(0x70);
matrix.setBrightness(5);
}
void loop() {
// 定义一个字符数组,用于保存要显示的内容
char message[MATRIX_WIDTH * 2];
// 将文本复制到字符数组中,并在末尾添加空格
text.toCharArray(message, MATRIX_WIDTH * 2);
strcat(message, " ");
// 计算字符数组的长度
int messageLength = strlen(message);
// 定义字符数组的起始位置
int startIndex = 0;
// 循环滚动字符数组
while (true) {
// 清空点阵
matrix.clear();
// 计算当前要显示的字符在字符数组中的位置
int charIndex = startIndex % messageLength;
// 在点阵上绘制当前要显示的字符
for (int i = 0; i < MATRIX_WIDTH; i++) {
for (int j = 0; j < MATRIX_HEIGHT; j++) {
int pixelIndex = i + (j * MATRIX_WIDTH);
if (message[charIndex] & (1 << i)) {
matrix.drawPixel(pixelIndex, true);
}
}
}
// 显示点阵内容
matrix.writeDisplay();
// 延迟一定时间,使字符滚动
delay(100);
// 移动字符数组的起始位置
startIndex++;
}
}
```
该代码使用Adafruit_GFX和Adafruit_LEDBackpack库来控制LED点阵模块。在setup函数中,初始化点阵并设置亮度。在loop函数中,定义一个字符数组来保存要显示的文本,并循环滚动该字符数组。在每次循环中,清空点阵、计算当前要显示的字符在字符数组中的位置、在点阵上绘制当前要显示的字符、显示点阵内容、延迟一定时间以使字符滚动,并移动字符数组的起始位置。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)