跳转到主要内容

Interrupts

Interrupt

This library allows users to trigger a process interrupt function or enable/disable an interrupt function when the input to a pin changes value.

attachInterrupt

Description
Specifies a function to execute (call) when an external interrupt occurs (signal on external pin).
Syntax
attachInterrupt(num, void(*)(void) func, mode)
Parameters
num: The number of the interrupt number. Specify X of IntX described in the PinMap.
func: The function to call when the interrupt occurs
mode:
LOW (to trigger the interrupt whenever the pin is low)
CHANGE (to trigger the interrupt whenever the pin changes value)
FALLING (to trigger when the pin goes from high to low)
RISING (to trigger when the pin goes from low to high)
Returns
None

detachInterrupt

Description
Turns off the interrupt specified in attachInterrupt.
Syntax
detachInterrupt(num)
Parameters
num: The number of the interrupt number. Specify X of IntX described in the PinMap.
Returns
None

interrupts

Description
Re-enables the interrupt disabled in noInterrupts.
Syntax
interrupts()
Parameters
None
Returns
None

noInterrupts

Description
Disables an interrupt process. Use this when you need to protect the timing of a specific process; this can even be used to disable an important task run in the background.
Syntax
noInterrupts()
Parameters
None
Returns
None

Sample Program

This is a sample that generates an interrupt when you press SW0 (Int4).


#include <Arduino.h>
#define INTERRUPT_PIN PIN_SW0
#define INTERRUPT_NUM 4
    
void ext_interrupt(){
    digitalWrite(PIN_LED_RED, !digitalRead(INTERRUPT_PIN));
}
    
void setup() {
    Serial.begin(9600); // for PC
    
    pinMode(PIN_LED_RED, OUTPUT);
    digitalWrite(PIN_LED_RED, LOW);
    
    pinMode(INTERRUPT_PIN, INPUT);
    attachInterrupt(INTERRUPT_NUM, ext_interrupt, CHANGE);
}
    
void loop(){
}

支持

支持社区

支持社区

在线询问瑞萨电子工程社群的技术人员,快速获得技术支持。
浏览常见问题解答

常见问题

浏览我们的知识库,了解常见问题的解答。
提交工单

提交工单

需要咨询技术性问题或提供非公开信息吗?