attachInterrupt()
Description
This command specifies a named Interrupt Service Routine (ISR) to call on when an interrupt occurs. (Note: this function will only work when the timer is in interrupt mode)
Syntax
TimerWDT.attachInterrupt(isr)
TimerWDT.attachInterrupt(isr, time)
Parameters
isr
:The name of the function to be called whenever an interrupt event happens.
time
:Sets time duration and interval parameters (optional) in microseconds (μs).
Return
None
Example
Set up watch dog timer in interrupt mode, LED lights on and off every 100ms:
#include <TimerWDT.h> void setup() { pinMode(13, OUTPUT); TimerWDT.initialize(100000); // sets up 100ms time intervals. TimerWDT.attachInterrupt( timerIsr ); // attaches ISR, executed once every 100ms. } void loop() {} // ISR void timerIsr() { // turns the LED lights on and off. 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.