Arduino入門:割り込み

Arduinoの割込みについて解説します。

interrupts

interruptsは、noInterrupts関数によって停止した割り込みを有効にします。 Aruduinoでは、割り込みはデフォルトで有効化されており、バックグラウンドで重要なタスクを処理しています。割り込みが無効の間、シリアル通信の受信等幾つかのサービスが無効になる場合があります。なお、割り込みはコードのタイミングを若干乱すので、タイミングが重要なアプリケーションによっては無効にした方が良いかも知れません。

//Arduino Sketch Example: interrupts
//Date: 2015.1.18
//Edited and Modified by: easy labo
//Original Source: Arduino Reference (http://arduino.cc/en/Reference/HomePage)

//Syntax
interrupts()

//Description
/*
Re-enables interrupts (after they've been disabled by noInterrupts()). Interrupts allow certain important tasks to happen in the background and are enabled by default. Some functions will not work while interrupts are disabled, and incoming communication may be ignored. Interrupts can slightly disrupt the timing of code, however, and may be disabled for particularly critical sections of code.
*/

//Example

void setup() {}

void loop()
{
  noInterrupts();
  // critical, time-sensitive code here
  interrupts();
  // other code here
}

Creative Commons Attribution-ShareAlike 3.0 License (CC BY-SA 3.0)
Arduino Reference:interrupts()” by Arduino Team, used under CC BY-SA 3.0/ easy labo made some changes and comments to the original

noInterrupts

noInterruptsは、割り込みを無効にします。

//Arduino Sketch Example: noInterrupts
//Date: 2015.1.18
//Edited and Modified by: easy labo
//Original Source: Arduino Reference (http://arduino.cc/en/Reference/HomePage)
//

//Syntax
noInterrupts()

//Description
/*
Disables interrupts (you can re-enable them with interrupts()). Interrupts allow certain important tasks to happen in the background and are enabled by default. Some functions will not work while interrupts are disabled, and incoming communication may be ignored. Interrupts can slightly disrupt the timing of code, however, and may be disabled for particularly critical sections of code.
*/

//Example

void setup() {}

void loop()
{
  noInterrupts();
  // critical, time-sensitive code here
  interrupts();
  // other code here
}

Creative Commons Attribution-ShareAlike 3.0 License (CC BY-SA 3.0)
Arduino Reference:noInterrupts()” by Arduino Team, used under CC BY-SA 3.0/ easy labo made some changes and comments to the original
→その他のArduino関連情報

Sponsored Link