initialize()

Description

Initializes the watch dog timer from 86Duino and sets up the mode type.

Syntax


TimerWDT.initialize()
TimerWDT.initialize(time)
TimerWDT.initialize(time, mode)

Parameter

time:Sets the cycle time for the watch dog timer in microseconds. The limit of the time interval is 512 seconds(512000000μs);If there is no value, the default is 500ms (500000μs).

mode:Sets up the watch dog timer mode. The mode type is boolean and the default value is false

  • true:Watch dog mode(Once it reaches the designated interval, the 86Duino will reboot)
  • false:Interrupt mode(Once it reaches the designated interval, it will execute the ISR once. This is the default value)

Return

None

Example

Set up watch dog timer to interrupt mode which will turn the LED on and off every 100ms:

#include <TimerWDT.h>
 
void setup() 
{
  pinMode(13, OUTPUT);
  TimerWDT.initialize(100000); // sets time interval to 100ms
  TimerWDT.attachInterrupt( timerIsr ); // attaches ISR, executed every 100ms
}
 
void loop() {}

// ISR
void timerIsr()
{
    // turn the LED on and off
    digitalWrite( 13, digitalRead( 13 ) ^ 1 );
}

Set up watch dog timer to watch dog mode which will reboot the system every 30 seconds:

#include <TimerWDT.h>
 
void setup() 
{
  TimerWDT.initialize(30000000, true); // set up a 30s time interval
}
 
void loop() {
  // user function
}

See also

attachInterrupt()()
detachInterrupt()
setPeriod()
reset()
isResetByWDT()
stop()


Libraries Reference Home

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.