Arduinoのピンに接続された信号が変化したときに割り込みを行うための外部割り込み関数です。
●引数
interrupt | 割り込みに使うピン |
ISR | 割り込み発生で呼び出す関数 |
mode | 割り込み発生の条件 ・LOW:信号がLOWの間ずっと ・CHANGE:信号が変化をした時 ・RISING:立ち上がり ・FALLING:立ち下がり |
●割り込みピンの割り付け
Board | Digital Pins Usable For Interrupts |
Uno, Nano, Mini, other 328-based | 2, 3 |
Mega, Mega2560, MegaADK | 2, 3, 18, 19, 20, 21 |
Micro, Leonardo, other 32u4-based | 0, 1, 2, 3, 7 |
Zero | all digital pins, except 4 |
MKR1000 Rev.1 | 0, 1, 4, 5, 6, 7, 8, 9, A1, A2 |
Due | all digital pins |
●Example from Arduino Web Site
[c]
const byte ledPin = 13;
const byte interruptPin = 2;
volatile byte state = LOW;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), blink, CHANGE);
}
void loop() {
digitalWrite(ledPin, state);
}
void blink() {
state = !state;
}
[/c]