搓个MOSS家人们

本文最后更新于 2023年2月21日 中午

一、线序

1、0.91 inch OLED屏幕

  • 黄:VCC
  • 蓝:GND
  • 紫:SDA
  • 绿:SCL

2、1.54 inch LCD屏幕

  • 紫:VCC
  • 白:GND
  • 绿:DIN
  • 橙:CLK
  • 黄:CS
  • 蓝:DC
  • 棕:RST
  • 灰:BL

二、录制素材

随便找个录音软件,录制三段关键词的音频,之后使用ffmpeg转成指定格式

1
2
3
ffmpeg -i input_audio.mp3 -acodec pcm_s16le -ar 16000 -ac 1 record1.wav
ffmpeg -i input_audio.mp3 -acodec pcm_s16le -ar 16000 -ac 1 record2.wav
ffmpeg -i input_audio.mp3 -acodec pcm_s16le -ar 16000 -ac 1 record3.wav

三、问问AI

1、arduino相关

编写arduino程序,从串口读入一个十六进制数,将其转化为二进制并以数组的形式存储每一位

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// 定义变量
byte hex;
byte binary[8];

void setup()
{
Serial.begin(9600); // 初始化串口
}

void loop()
{
if(Serial.available() > 0) // 如果串口有可读数据
{
hex = Serial.read(); // 读取一个字节的数据
for(int i=0; i<8; i++) // 将十六进制数转换为二进制数,并存入数组
{
binary[i] = (hex>>i)&0x01;
}
for(int i=7; i>=0; i--) // 输出二进制数
{
Serial.print(binary[i]);
}
Serial.println(); // 换行
}
}

屏幕滚动显示

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//定义屏幕参数
#define TFT_DC 9
#define TFT_CS 10
#define TFT_RST 8

//定义字体
#define FONT_SIZE_SMALL 1
#define FONT_SIZE_MEDIUM 2
#define FONT_SIZE_LARGE 3

//定义滚动方向
#define SCROLL_UP 0
#define SCROLL_DOWN 1

//定义滚动速度
#define SCROLL_SLOW 0
#define SCROLL_MEDIUM 1
#define SCROLL_FAST 2

//定义滚动字符串
String scroll_str = "Arduino ST7789滚动显示屏";

//定义滚动字符串长度
int str_len = scroll_str.length();

//定义滚动位置
int scroll_pos = 0;

//定义滚动方向
int scroll_dir = SCROLL_UP;

//定义滚动速度
int scroll_speed = SCROLL_SLOW;

//定义字体大小
int font_size = FONT_SIZE_MEDIUM;

//定义滚动延时
int scroll_delay = 200;

//定义屏幕实例
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);

void setup()
{
//初始化屏幕
tft.initR(INITR_BLACKTAB);
tft.fillScreen(ST77XX_BLACK);
tft.setRotation(3);
}

void loop()
{
//设置字体大小
tft.setTextSize(font_size);

//滚动显示字符串
scrollText(scroll_str, scroll_pos, scroll_dir, scroll_speed);

//更新滚动位置
scroll_pos++;
if (scroll_pos > str_len * font_size * 6)
{
scroll_pos = 0;
}

//延时
delay(scroll_delay);
}

//滚动显示字符串
void scrollText(String str, int pos, int dir, int speed)
{
//计算滚动位置
int x_pos = pos;
if (dir == SCROLL_DOWN)
{
x_pos = -pos;
}

//根据滚动速度设置延时
int delay_time = 200;
if (speed == SCROLL_MEDIUM)
{
delay_time = 150;
}
else if (speed == SCROLL_FAST)
{
delay_time = 100;
}

//计算滚动字符串长度
int str_len = str.length();

//滚动显示字符串
for (int i = 0; i < str_len; i++)
{
//设置滚动位置
tft.setCursor(x_pos, 0);

//获取滚动字符
char c = str.charAt(i);

//显示滚动字符
tft.print(c);

//更新滚动位置
x_pos += font_size * 6;
if (x_pos > tft.width())
{
x_pos = 0;
}

//延时
delay(delay_time);
}
}

搓个MOSS家人们
https://www.aye10032.com/2023/01/27/2023-02-17-moss/
作者
Aye10032
发布于
2023年1月27日
更新于
2023年2月21日
许可协议