attachInterrupt

设置中断


语法
 void attachInterrupt(uint8 pin, voidFuncPtr handler, ExtIntTriggerMode mode)"


参数


返回值


示例
volatile int state = LOW; 
void setup() {
    pinMode(LED_BUILTIN, OUTPUT);
    pinMode(0, INPUT);
    attachInterrupt(0, blink, CHANGE);
}

void loop() {
    digitalWrite(LED_BUILTIN, state);
}

void blink() {
    if (state == HIGH) {
        state = LOW;
    } else { 
        state = HIGH;
    }
}