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.
