setPeriod()
描述
設定看門狗計時器的時間週期。
語法
TimerWDT.setPeriod(time)
參數
time:時間週期,單位為微秒(us)。
回傳
無回傳值
範例
設定看門狗計時器為計時中斷模式, 每隔 200ms 點亮和熄滅 LED:
#include <TimerWDT.h>
void setup()
{
pinMode(13, OUTPUT);
TimerWDT.initialize();
TimerWDT.setPeriod(200000); // 時間週期設定為 200ms
TimerWDT.attachInterrupt( timerIsr ); // 掛載使用者 ISR, 每隔 200ms 執行一次
}
void loop() {}
// 使用者 ISR
void timerIsr()
{
// 交替點亮和熄滅 LED 燈
digitalWrite( 13, digitalRead( 13 ) ^ 1 );
}
See also
- initialize()
- attachInterrupt()
- 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.
