File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -89,3 +89,72 @@ AirMCU 上的 GPIO 外设支持中断。
8989```cpp
9090void attachInterrupt(uint32_t pin, callback_function_t callback, uint32_t mode)
9191```
92+
93+ - ` pin ` :要配置的引脚号。
94+ - ` callback ` :中断回调函数。
95+ - ` mode ` :中断触发模式。可以是以下值之一:
96+
97+ - ` CHANGE ` :引脚状态发生变化时触发中断。
98+ - ` RISING ` :引脚状态从低电平变为高电平时触发中断。
99+ - ` FALLING ` :引脚状态从高电平变为低电平时触发中断。
100+ - ` LOW ` :引脚状态为低电平时触发中断。
101+ - ` HIGH ` :引脚状态为高电平时触发中断。
102+
103+ ### detachInterrupt
104+
105+ 要从特定引脚分离中断,请使用 ` detachInterrupt ` 函数来分离 GPIO。
106+
107+ ``` cpp
108+ void detachInterrupt (uint32_t channel)
109+ ```
110+
111+ - `channel`:要分离的引脚号。
112+
113+ ## 示例代码
114+
115+ ### GPIO 输入和输出模式
116+
117+ ```cpp
118+ const auto LED = PB0;
119+ const auto BUTTON = PF4;
120+
121+ uint8_t stateLED = 0;
122+
123+ void setup() {
124+ pinMode(LED, OUTPUT);
125+ pinMode(BUTTON,INPUT_PULLUP);
126+ }
127+
128+ void loop() {
129+ if(!digitalRead(BUTTON)){
130+ stateLED = stateLED^1;
131+ digitalWrite(LED,stateLED);
132+ }
133+ }
134+ ```
135+
136+ ### GPIO 中断
137+
138+ ``` cpp
139+ const auto ledPin = PB0;
140+
141+ const auto interruptPin = PF4;
142+
143+ volatile byte state = LOW;
144+
145+ void setup () {
146+ pinMode (ledPin, OUTPUT);
147+
148+ pinMode (interruptPin, INPUT_PULLDOWN);
149+
150+ attachInterrupt (digitalPinToInterrupt (interruptPin), blink, CHANGE);
151+ }
152+
153+ void loop () {
154+ digitalWrite (ledPin, state);
155+ }
156+
157+ void blink () {
158+ state = !state;
159+ }
160+ ```
You can’t perform that action at this time.
0 commit comments