Basic Library
Digital I/O
Analog I/O
Advanced I/O
Time
Math
Trigonometry
Random Numbers
Bits and Bytes
Interrupts
Serial Comm.
Standard Library
Servo Motor
Stepping Motor
Liquid Crystal
EEPROM
SPI
I2C (Wire)
SD Card
SD (File Operations)
Ethernet
Ethernet (Server)
Ethernet (Client)
Firmata
Periodic Operation
Power Save
Clock (RTC)
SoftwareSerial
Utility
Periodic Operation
This library allows users to call a function periodically.
attachCyclicHandler
Description
Specifies a cyclic call back function. The specified call back function is called at the cycle specified by this function.
Syntax
attachCyclicHandler(unsigned char number, void(*)(unsigned long) function, unsigned int time)
Parameters
number: ID (0 to 7)
function: Function of the interval timer interrupt
time: Interval time in msReturns
None
detachCyclicHandler
Description
Turns off the interval call back function.
Syntax
detachCyclicHandler(unsigned char number)
Parameters
number: ID (0 to 7)
Returns
None
Note
The cyclic handler is executed in a loop.
attachIntervalTimerHandler
Description
Specifies a call back function executed in the interval timer interrupt handler. The specified call back function is called every 1ms of the interval timer interrupt once it's attached.
Syntax
attachIntervalTimerHandler(void(*)(unsigned long) function)
Parameters
function: Name of the handler
Returns
None
Remark
The libraries below can be called in the handler.
pinMode(), digitalWrite(), digitalRead(), millis(), micros(), delayMicroseconds(), min(), max(), constrain(), map(), lowByte(), highByte(), bitRead(), bitWrite(), bitSet(), bitClear(), bit(), randomSeed(), random()
Note: pinMode(), digitalWrite() may use the pins that are used in function loop(), which may causes a mis-operation.
detachIntervalTimerHandler
Description
Turns off the call back function in the interval timer interrupt handler.
Syntax
detachIntervalTimerHandler()
Parameters
None
Returns
None
attachMicroIntervalTimerHandler
Description
Specifies a call back function executed in the interval timer interrupt handler. The specified call back function is called in a time specified parameter[us].
Syntax
attachIntervalTimerHandler(void(*)(unsigned long) function, uint16_t interval)
Parameters
function: Name of the handler
interval: Interval time[us]Returns
None
Remark
The following libraries can be called in the handler:
pinMode(), digitalWrite(), digitalRead(), millis(), micros(), delayMicroseconds(), min(), max(), constrain(), map(), lowByte(), highByte(), bitRead(), bitWrite(), bitSet(), bitClear(), bit(), randomSeed(), random()
Note: pinMode(), digitalWrite() may use the pins that are used in function loop(), which may causes a mis-operation.
tone() is disabled after setting a function. Modify HOOK_TIMER_CHANNEL when you want to change from tone().
detachIntervalTimerHandler
Description
Turns off the call back function in the interval timer interrupt handler.
Syntax
detachIntervalTimerHandler()
Parameters
None
Returns
None
Example
This example calls the cyclic function every 100ms, and outputs the returned time every 500ms.
#include <Arduino.h>
void test_cyclic_handler(unsigned long u32ms);
unsigned long time;
void setup()
{
Serial.begin(9600);
attachCyclicHandler(0, test_cyclic_handler, 100);
}
void loop()
{
Serial.println(time);
delay(500);
}
void test_cyclic_handler(unsigned long u32ms)
{
time = u32ms;
}