feat: sync arduino and python board configurations

This commit is contained in:
yczpf2019
2026-01-24 16:13:38 +08:00
parent 01b756fed8
commit c6dc5537f0
851 changed files with 47772 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
## 输入/输出
输入/输出所包含的指令主要分为四部分控制管脚的输入输出按信号类型可分为数字信号和模拟信号、中断、脉冲长度及ShiftOut。
- 输入输出:数字输入、数字输出、模拟输入、模拟输出
- 中断控制:定义中断,取消中断
- 脉冲长度
- 移位输出
<img src="{default}/images/inout/input-output.png" alt="输入/输出分类" style="zoom:50%;" />

View File

@@ -0,0 +1,41 @@
## 数字输出
<img src="{default}/images/inout/digital-pin-output.png" alt="数字输出" style="zoom:67%;" />
```arduino
digitalWrite(2, HIGH);
digitalWrite(2, LOW);
```
### 描述
> 给一个数字引脚写入HIGH或者LOW。
### 参数
- 管脚: 引脚编号如1510A0A3
- 值: 高 或 低
### 范例
将13号端口设置为高电平延迟一秒然后设置为低电平再延迟一秒如此往复。
<img src="{default}/images/inout/digital-pin-output-example.png" alt="数字输出示例" style="zoom:67%;" />
```arduino
void setup(){
pinMode(13, OUTPUT);
}
void loop(){
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW);
delay(1000);
}
```
<div class="layui-card" style="box-shadow: 1px 1px 4px 1px rgb(0 0 0 / 20%);">
<div class="layui-card-header icon-attention-circled" style="background: #f0b37e;color:#fff;font-size:16px;">注意</div>
<div class="layui-card-body" style="background: #ffedcc;">数字13号引脚难以作为数字输入使用因为大部分的控制板上使用了一颗LED与一个电阻连接到他。如果启动了内部的20K上拉电阻他的电压将在1.7V左右而不是正常的5V因为板载LED串联的电阻把他使他降了下来这意味着他返回的值总是LOW。如果必须使用数字13号引脚的输入模式需要使用外部上拉下拉电阻</div>
</div>

View File

@@ -0,0 +1,42 @@
## 数字输入
<img src="{default}/images/inout/digital-input.png" alt="数字输入" style="zoom:67%;" />
```arduino
digitalRead(2);
```
### 描述
> 读取指定引脚的值HIGH或LOW。
### 参数
- 管脚: 引脚编号如1,5,10,A0,A3
### 返回
HIGH 或 LOW
### 范例
读取数字0号引脚的值并通过串口打印出来。
<img src="{default}/images/inout/digital-input-example.png" alt="数字输入示例" style="zoom:67%;" />
```arduino
void setup(){
pinMode(2, INPUT);
Serial.begin(9600);
}
void loop(){
Serial.println(digitalRead(2));
delay(1000);
}
```
<div class="layui-card" style="box-shadow: 1px 1px 4px 1px rgb(0 0 0 / 20%);">
<div class="layui-card-header icon-attention-circled" style="background: #f0b37e;color:#fff;font-size:16px;">注意</div>
<div class="layui-card-body" style="background: #ffedcc;">如果引脚悬空digitalRead()会返回HIGH或LOW随机变化。</div>
</div>

View File

@@ -0,0 +1,44 @@
## 模拟输出
<img src="{default}/images/inout/analog-pin-output.png" alt="模拟输出" style="zoom:67%;" />
```arduino
analogWrite(3, 100);
```
### 描述
> 从一个引脚输出模拟值PWM。 可用于让LED以不同的亮度点亮或驱动电机以不同的速度旋转。
### 参数
- 管脚:引脚编号如3,5,6,9,10,11不同的开发板模拟输入引脚数量不一样。
- 赋值:0完全关闭到255完全打开之间。
### 范例
控制LED实现呼吸灯效果。
<img src="{default}/images/inout/analog-pin-output-example.png" alt="模拟输出示例" style="zoom:67%;" />
```arduino
void setup(){
}
void loop(){
for (int i = 0; i <= 255; i = i + (1)) {
analogWrite(10, i);
delay(10);
}
for (int i = 255; i >= 0; i = i + (-1)) {
analogWrite(10, i);
delay(10);
}
}
```
<div class="layui-card" style="box-shadow: 1px 1px 4px 1px rgb(0 0 0 / 20%);">
<div class="layui-card-header icon-attention-circled" style="background: #f0b37e;color:#fff;font-size:16px;">注意</div>
<div class="layui-card-body" style="background: #ffedcc;">analogWrite函数与模拟引脚、analogRead函数没有直接关系。 在大多数Arduino板ATmega168或ATmega328只有引脚356910和11可以实现该功能。 在Arduino Mega上引脚2到13可以实现该功能。</div>
</div>

View File

@@ -0,0 +1,43 @@
## 模拟输入
<img src="{default}/images/inout/analog-pin-input.png" alt="模拟输入" style="zoom: 67%;" />
```arduino
analogRead(A0);
```
### 描述
> 从指定的模拟引脚读取数据值。
>
> Arduino板包含一个6通道Mini和Nano有8个通道Mega有16个通道10位模拟数字转换器。这意味着它将0至5伏特之间的输入电压映射到0至1023之间的整数值。
### 参数
- 管脚: 引脚编号如A0,A1,A2,A3不同的开发板模拟输入引脚数量不一样。
### 返回
从0到1023的整数值
### 范例
读取模拟A0引脚的值并通过串口打印出来。
<img src="{default}/images/inout/analog-pin-input-example.png" alt="模拟输入示例" style="zoom: 67%;" />
```arduino
void setup(){
pinMode(A0, INPUT);
Serial.begin(9600);
}
void loop(){
Serial.println(analogRead(A0));
}
```
<div class="layui-card" style="box-shadow: 1px 1px 4px 1px rgb(0 0 0 / 20%);">
<div class="layui-card-header icon-attention-circled" style="background: #f0b37e;color:#fff;font-size:16px;">注意</div>
<div class="layui-card-body" style="background: #ffedcc;">如果模拟输入引脚没有连入电路由analogRead()返回的值将根据多项因素(例如其他模拟输入引脚,你的手靠近板子等)产生波动。</div>
</div>

View File

@@ -0,0 +1,84 @@
## 硬件中断
<img src="{default}/images/inout/interrupt-pin.png" alt="中断管脚" style="zoom:67%;" />
```arduino
void attachInterrupt_fun_RISING_2() {
}
void setup(){
pinMode(2, INPUT_PULLUP);
}
void loop(){
attachInterrupt(digitalPinToInterrupt(2),attachInterrupt_fun_RISING_2,RISING);
}
```
### 1.1 描述
> 当发生外部中断时,调用一个指定函数。当中断发生时,该函数会取代正在执行的程序。
>
> 大多数的Arduino板有两个外部中断0数字引脚2和1数字引脚3
>
> Arduino Mege有四个外部中断数字2引脚21320针4引脚195引脚18
>
> ESP8266 、ESP32系列有更多中断。
### 1.2 参数
- 管脚: 引脚编号如2,3不同的开发板中断引脚不一样。
- 模式:
> 改变:当引脚电平发生改变时,触发中断
>
> 上升:当引脚由低电平变为高电平时,触发中断
>
> 下降:当引脚由高电平变为低电平时,触发中断
### 1.3 范例
利用2号引脚中断控制13号引脚的LED亮灭。
<img src="{default}/images/inout/interrupt-pin-example.png" alt="中断管脚示例" style="zoom:67%;" />
```arduino
volatile boolean state;
void attachInterrupt_fun_RISING_2() {
state = !state;
digitalWrite(13,state);
}
void setup(){
state = false;
pinMode(2, INPUT_PULLUP);
pinMode(13, OUTPUT);
attachInterrupt(digitalPinToInterrupt(2),attachInterrupt_fun_RISING_2,RISING);
}
void loop(){
}
```
<div class="layui-card" style="box-shadow: 1px 1px 4px 1px rgb(0 0 0 / 20%);">
<div class="layui-card-header icon-attention-circled" style="background: #f0b37e;color:#fff;font-size:16px;">注意</div>
<div class="layui-card-body" style="background: #ffedcc;">当中断函数发生时delay()和millis()的数值将不会继续变化。当中断发生时,串口收到的数据可能会丢失。你应该声明一个变量来在未发生中断时储存变量。</div>
</div>
## 取消硬件中断
<img src="{default}/images/inout/detach-interrupt-pin.png" alt="取消中断" style="zoom:67%;" />
```arduino
detachInterrupt(digitalPinToInterrupt(2));
```
### 2.1 描述
> 关闭给定的中断。
### 2.2 参数
- 管脚: 引脚编号如23不同的开发板中断引脚不一样。

View File

@@ -0,0 +1,17 @@
## 管脚模式
<img src="{default}/images/inout/pinmode.png" alt="管脚模式" style="zoom:67%;" />
```arduino
pinMode(2, INPUT);
```
### 描述
> 设置指定管脚的模式。
### 参数
- 管脚: 引脚编号如23不同的开发板中断引脚不一样。
- 模式: 要将管脚设置成的模式,包括输入、输出、上拉输入。

View File

@@ -0,0 +1,42 @@
## 脉冲长度
<img src="{default}/images/inout/pin-pulseIn.png" alt="脉冲长度" style="zoom:67%;" />
```arduino
pulseIn(0, HIGH);
pulseIn(0, HIGH, 1000000);
```
### 描述
> 读取一个引脚的脉冲HIGH或LOW
>
> 例如如果value是HIGHpulseIn()会等待引脚变为HIGH开始计时再等待引脚变为LOW并停止计时。返回脉冲的长度单位微秒。如果在指定的时间内无脉冲函数返回。 此函数的计时功能由经验决定长时间的脉冲计时可能会出错。计时范围从10微秒至3分钟。1秒=1000毫秒=1000000微秒
### 参数
- 管脚:你要进行脉冲计时的引脚号int
- 状态:要读取的脉冲类型HIGH或LOWint
- 超时 (可选):指定脉冲计数的等待时间单位为微秒默认值是1秒unsigned long
### 返回
脉冲长度微秒如果等待超时返回0unsigned long
### 范例
读取6号引脚脉冲时长。
<img src="{default}/images/inout/pin-pulseIn-example.png" alt="脉冲长度示例" style="zoom:67%;" />
```arduino
void setup(){
pinMode(6, INPUT);
Serial.begin(9600);
}
void loop(){
Serial.println(pulseIn(6, HIGH));
}
```

View File

@@ -0,0 +1,19 @@
## ShiftOut
<img src="{default}/images/inout/shiftout.png" alt="image-20220528150921075" style="zoom:67%;" />
```arduino
shiftOut(2, 3, MSBFIRST, 0); // 高位先入
shiftOut(2, 3, LSBFIRST, 0); // 低位先入
```
### 描述
> 将一个数据的一个字节一位一位的移出。从最高有效位(最左边)或最低有效位(最右边)开始。依次向数据脚写入每一位,之后时钟脚被拉高或拉低,指示刚才的数据有效。
### 参数
- 数据管脚:输出每一位数据的引脚(int)
- 时钟管脚:时钟脚,当数据管脚有值时此引脚电平变化(int)
- 顺序:输出位的顺序,最高位优先或最低位优先
- 数值: 要移位输出的数据(byte)

View File

@@ -0,0 +1,57 @@
## 软件中断
<img src="{default}/images/inout/software-interrupt.png" alt="软件中断" style="zoom:67%;" />
```arduino
#include <PinChangeInt.h>
void attachPinInterrupt_fun_RISING_2() {
}
void setup(){
pinMode(2, INPUT);
PCintPort::attachInterrupt(2,attachPinInterrupt_fun_RISING_2,RISING);
}
void loop(){
}
```
### 1.1 描述
> 当发生外部中断时,调用一个指定函数。当中断发生时,该函数会取代正在执行的程序。
>
> 本模块为模拟中断,支持所有管脚使用。
### 1.2 参数
- 管脚: 引脚编号如2,3不同的开发板中断引脚不一样。
- 模式:
改变:当引脚电平发生改变时,触发中断上升:当引脚由低电平变为高电平时,触发中断下降:当引脚由高电平变为低电平时,触发中断
### 1.3 范例
利用中断控制13号引脚的LED亮灭。
<div class="layui-card" style="box-shadow: 1px 1px 4px 1px rgb(0 0 0 / 20%);">
<div class="layui-card-header icon-attention-circled" style="background: #f0b37e;color:#fff;font-size:16px;">注意</div>
<div class="layui-card-body" style="background: #ffedcc;">当中断函数发生时delay()和millis()的数值将不会继续变化。当中断发生时,串口收到的数据可能会丢失。你应该声明一个变量来在未发生中断时储存变量。</div>
</div>
## 取消软件中断
<img src="{default}/images/inout/software-detachInterrupt.png" alt="取消软件中断" style="zoom:67%;" />
```arduino
PCintPort::detachInterrupt(2);
```
### 2.1 描述
> 关闭给定的中断。
### 2.2 参数
- 管脚: 引脚编号如23不同的开发板中断引脚不一样。

View File

@@ -0,0 +1,56 @@
## 多功能按键
<img src="{default}/images/inout/OneButton.png" alt="多功能按键" style="zoom:67%;" />
```arduino
#include <OneButton.h>
OneButton button2(2, false);
void attachClick2() {
}
void setup(){
button2.attachClick(attachClick2);
}
void loop(){
button2.tick();
}
```
### 描述
> 设置特定管脚连接的按钮为多功能按钮,并确定不同模式下执行不同的程序。
### 参数
- 多功能按键: 引脚编号如1,5,10A0A3
- 模式: 单击 双击 长按开始 长按中 长按结束
### 范例
将2号端口连接的按钮设置为多功能按钮单击时串口提示“one Click”。
<img src="{default}/images/inout/OneButton-example.png" alt="多功能按键示例" style="zoom:67%;" />
```arduino
#include <OneButton.h>
OneButton button2(2, false);
void attachClick2() {
Serial.println("one click");
}
void setup(){
button2.attachClick(attachClick2);
Serial.begin(9600);
}
void loop(){
button2.tick();
}
```