Skip to main content

Periodic Operation

Periodic Operation

This library allows users to call a function periodically. Three types of timers are prepared. MsTimer2, one of types, is compatible with Arduino One described in Arduino Playground.

It is necessary to specify #include for using MsTimer2.

MsTimer2::set

Description
Specifies a call back function executed in the specified interval timer interrupt handler.
Syntax
MsTimer2::set(unsigned long ms, void (*function)())
Parameters
ms: Interval(ms)
function: Function name
Returns
None
Notes
The handler is executed by disabled interrupt. In case of executing with use of interrupt, permit an interrupt by interrupt().

MsTimer2::start

Description
Start the timer after set
Syntax
MsTimer2::start()
Parameters
None
Returns
None

MsTimer2::stop

Description
Stop the timer
Syntax
MsTimer2::stop()
Parameters
None
Returns
None

Sample Program

This sample uses MsTimer2.


#include <Arduino.h>
#include <MsTimer2.h>
void using_mstimer2() {
  static boolean output = HIGH;
  digitalWrite(PIN_LED0, output);
  output = !output;
}
  
void setup() {
  pinMode(PIN_LED0, OUTPUT);
  
  MsTimer2::set(100, using_mstimer2); // 500ms period
  MsTimer2::start();
  
}
  
void loop() {
}