attachInterrupt()
描述
掛載使用者 ISR,並同時啟動看門狗計時器。(註:此函式只有在計時中斷模式下才有作用。)
語法
TimerWDT.attachInterrupt(isr)
TimerWDT.attachInterrupt(isr, time)
參數
isr:執行的函式名稱。
time:設定時間週期(可選參數,非必要),單位為 us。
回傳
無回傳值
範例
設定看門狗計時器為計時中斷模式,每隔 100ms 點亮和熄滅 LED:
#include <TimerWDT.h>
void setup()
{
pinMode(13, OUTPUT);
TimerWDT.initialize(100000); // 設定 100ms 時間間隔
TimerWDT.attachInterrupt( timerIsr ); // 掛載使用者 ISR,每隔 100ms 執行一次
}
void loop() {}
// 使用者 ISR
void timerIsr()
{
// 交替點亮和熄滅 LED 燈
digitalWrite( 13, digitalRead( 13 ) ^ 1 );
}
See also
- detachInterrupt()
The text of the 86Duino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.
