detachInterrupt()

Last revision:2025/04/24

名称

detachInterrupt()

説明

以前設定した割り込みを抑制する。

書式

この関数は以下の種類がある。

  • detachInterrupt(digitalPinToInterrupt(pin)) (推奨)
  • detachInterrupt(interrupt) (非推奨)
  • detachInterrupt(pin) (非推奨。特定のボードでのみ動作する)

C言語シグネチャ(avr)

  • void detachInterrupt(uint8_t digitalPinToInterrupt(pin)); (推奨);
  • void detachInterrupt(uint8_t interruptNum); (非推奨)

引数

この関数は以下の引数を受け付ける。

interrupt割り込みを抑制する割り込みの番号。詳細は attachInterrupt()を参照。
pin割り込みを抑制するピン番号。

戻り値

なし。

コード例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
void setup() {
  // Attach an interrupt on digital pin 2 (assuming you're using it with a button or sensor)
  //  attachInterrupt(digitalPinToInterrupt(2), myInterruptRoutine, RISING);

  // ... other setup code ...

  // Later, you can detach the interrupt when you no longer need it
  detachInterrupt(digitalPinToInterrupt(2)); // or detachInterrupt(2);
}

void loop() {
  // ... your main loop code ...
}

void myInterruptRoutine() {
  // This function will be executed when the interrupt on pin 2 is triggered
  // and it's still attached.  After detachInterrupt(), this routine won't be called.
}

参照

オリジナルのページ

https://docs.arduino.cc/language-reference/en/functions/external-interrupts/detachInterrupt/

実装の解析

detachInterrupt()

最終更新日

July 12, 2026

inserted by FC2 system